From nobody Thu Nov 28 17:51:00 2024 Received: from mx.treblig.org (mx.treblig.org [46.235.229.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 730833D0D5 for ; Sun, 29 Sep 2024 21:03:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.229.95 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727643826; cv=none; b=sWGex7gbw0MyykcTm8w1v79VyvIFeoWYYhnLq+zugQ9NRt9REBxh1KQcu+elUvO4HCkOqPjpTc9nlTpSR0lWK3iYgN00Q0kEy5gFDoSUxueCC6PbA2ZETptb3o+T+/8J66hoF03bo1W2FNlkd7OCtquSRyw0HUdRfVaUnalQNXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727643826; c=relaxed/simple; bh=ULDZspxAgAQy08EWCIdaUffR987wrVbnd/ivaiMYCZ0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=m/OikXeMXbP5OA7AH5ZDc7ZifP2C/KIbmSn7BzJcIav/g4Fke7FqrmCdppMOYwPBLbcejCAT6APQYe9r9wqHxuHo1X49NbsjRLARTDj7PMG1YptmUC51A/ASJhDN1H0iBlwoiFDpdImor12ULKMqPpvOy80LeVnB7FT13ebyR5E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=treblig.org; spf=pass smtp.mailfrom=treblig.org; dkim=pass (2048-bit key) header.d=treblig.org header.i=@treblig.org header.b=fATAOzOb; arc=none smtp.client-ip=46.235.229.95 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=treblig.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=treblig.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=treblig.org header.i=@treblig.org header.b="fATAOzOb" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=treblig.org ; s=bytemarkmx; h=MIME-Version:Message-ID:Date:Subject:From:Content-Type:From :Subject; bh=m1PzQTIEDVxxlxs7sA9n4mTcYa9KV3H44lmu6R++yWg=; b=fATAOzObw1YxcJqb 0Ywwy4Q0OYFN13XBERCkZwgziPtnslqHYxxjLLV/PURP93hCJdvLUnK1NPAlv1rDBDOkQ8fCU9UbO xrSlp6okGzQhWk1+q6Mm19hKJj+bpRtMCAaqTsFhNZXkrKbs67ZfG5yhR5qT5O/O495sFJhwKHdzd PaWnPEdvw2hxgPAzXBZgqfJ8QPKvSuYTI1PzhIaCDQ/+VpJc7TMWNTPlVTYaFZR8FSXWQwnwJYlMx wvnvlvnYOtcknR9KMxj9CnwtmpXQMehkQFmYuxxYnlw3Z3x/JLL4KhAyxvY72K0oChWmdBt65mX0w IIc89fLsCJc5LwI0NQ==; Received: from localhost ([127.0.0.1] helo=dalek.home.treblig.org) by mx.treblig.org with esmtp (Exim 4.96) (envelope-from ) id 1sv14p-007qty-0J; Sun, 29 Sep 2024 21:03:35 +0000 From: linux@treblig.org To: alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com Cc: airlied@gmail.com, simona@ffwll.ch, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, "Dr. David Alan Gilbert" Subject: [PATCH] drm/amd/powerplay: Delete unused function and maths library Date: Sun, 29 Sep 2024 22:03:33 +0100 Message-ID: <20240929210333.304747-1-linux@treblig.org> X-Mailer: git-send-email 2.46.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" We start with the function 'atomctrl_calculate_voltage_evv_on_sclk' which has been unused since 2016's commit e805ed83ba1c ("drm/amd/powerplay: delete useless files.") Remove it. It was the last user of the struct ATOM_ASIC_PROFILING_INFO_V3_4 remove it. It was also the last user of the entire fixed point maths library in ppevvmath.h. Remove it. Signed-off-by: Dr. David Alan Gilbert --- drivers/gpu/drm/amd/include/atombios.h | 72 --- .../drm/amd/pm/powerplay/hwmgr/ppatomctrl.c | 428 ------------- .../drm/amd/pm/powerplay/hwmgr/ppatomctrl.h | 2 - .../drm/amd/pm/powerplay/hwmgr/ppevvmath.h | 561 ------------------ 4 files changed, 1063 deletions(-) delete mode 100644 drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppevvmath.h diff --git a/drivers/gpu/drm/amd/include/atombios.h b/drivers/gpu/drm/amd/i= nclude/atombios.h index b78360a71bc9..e810366a3c83 100644 --- a/drivers/gpu/drm/amd/include/atombios.h +++ b/drivers/gpu/drm/amd/include/atombios.h @@ -5432,78 +5432,6 @@ typedef struct _ATOM_ASIC_PROFILING_INFO_V3_3 ULONG ulSDCMargine; }ATOM_ASIC_PROFILING_INFO_V3_3; =20 -// for Fiji speed EVV algorithm -typedef struct _ATOM_ASIC_PROFILING_INFO_V3_4 -{ - ATOM_COMMON_TABLE_HEADER asHeader; - ULONG ulEvvLkgFactor; - ULONG ulBoardCoreTemp; - ULONG ulMaxVddc; - ULONG ulMinVddc; - ULONG ulLoadLineSlop; - ULONG ulLeakageTemp; - ULONG ulLeakageVoltage; - EFUSE_LINEAR_FUNC_PARAM sCACm; - EFUSE_LINEAR_FUNC_PARAM sCACb; - EFUSE_LOGISTIC_FUNC_PARAM sKt_b; - EFUSE_LOGISTIC_FUNC_PARAM sKv_m; - EFUSE_LOGISTIC_FUNC_PARAM sKv_b; - USHORT usLkgEuseIndex; - UCHAR ucLkgEfuseBitLSB; - UCHAR ucLkgEfuseLength; - ULONG ulLkgEncodeLn_MaxDivMin; - ULONG ulLkgEncodeMax; - ULONG ulLkgEncodeMin; - ULONG ulEfuseLogisticAlpha; - USHORT usPowerDpm0; - USHORT usPowerDpm1; - USHORT usPowerDpm2; - USHORT usPowerDpm3; - USHORT usPowerDpm4; - USHORT usPowerDpm5; - USHORT usPowerDpm6; - USHORT usPowerDpm7; - ULONG ulTdpDerateDPM0; - ULONG ulTdpDerateDPM1; - ULONG ulTdpDerateDPM2; - ULONG ulTdpDerateDPM3; - ULONG ulTdpDerateDPM4; - ULONG ulTdpDerateDPM5; - ULONG ulTdpDerateDPM6; - ULONG ulTdpDerateDPM7; - EFUSE_LINEAR_FUNC_PARAM sRoFuse; - ULONG ulEvvDefaultVddc; - ULONG ulEvvNoCalcVddc; - USHORT usParamNegFlag; - USHORT usSpeed_Model; - ULONG ulSM_A0; - ULONG ulSM_A1; - ULONG ulSM_A2; - ULONG ulSM_A3; - ULONG ulSM_A4; - ULONG ulSM_A5; - ULONG ulSM_A6; - ULONG ulSM_A7; - UCHAR ucSM_A0_sign; - UCHAR ucSM_A1_sign; - UCHAR ucSM_A2_sign; - UCHAR ucSM_A3_sign; - UCHAR ucSM_A4_sign; - UCHAR ucSM_A5_sign; - UCHAR ucSM_A6_sign; - UCHAR ucSM_A7_sign; - ULONG ulMargin_RO_a; - ULONG ulMargin_RO_b; - ULONG ulMargin_RO_c; - ULONG ulMargin_fixed; - ULONG ulMargin_Fmax_mean; - ULONG ulMargin_plat_mean; - ULONG ulMargin_Fmax_sigma; - ULONG ulMargin_plat_sigma; - ULONG ulMargin_DC_sigma; - ULONG ulReserved[8]; // Reserved for future ASIC -}ATOM_ASIC_PROFILING_INFO_V3_4; - // for Polaris10/Polaris11 speed EVV algorithm typedef struct _ATOM_ASIC_PROFILING_INFO_V3_5 { diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c b/drivers/= gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c index b56298d9da98..fe24219c3bf4 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.c @@ -28,7 +28,6 @@ #include "ppatomctrl.h" #include "atombios.h" #include "cgs_common.h" -#include "ppevvmath.h" =20 #define MEM_ID_MASK 0xff000000 #define MEM_ID_SHIFT 24 @@ -677,433 +676,6 @@ bool atomctrl_get_pp_assign_pin( return bRet; } =20 -int atomctrl_calculate_voltage_evv_on_sclk( - struct pp_hwmgr *hwmgr, - uint8_t voltage_type, - uint32_t sclk, - uint16_t virtual_voltage_Id, - uint16_t *voltage, - uint16_t dpm_level, - bool debug) -{ - ATOM_ASIC_PROFILING_INFO_V3_4 *getASICProfilingInfo; - struct amdgpu_device *adev =3D hwmgr->adev; - EFUSE_LINEAR_FUNC_PARAM sRO_fuse; - EFUSE_LINEAR_FUNC_PARAM sCACm_fuse; - EFUSE_LINEAR_FUNC_PARAM sCACb_fuse; - EFUSE_LOGISTIC_FUNC_PARAM sKt_Beta_fuse; - EFUSE_LOGISTIC_FUNC_PARAM sKv_m_fuse; - EFUSE_LOGISTIC_FUNC_PARAM sKv_b_fuse; - EFUSE_INPUT_PARAMETER sInput_FuseValues; - READ_EFUSE_VALUE_PARAMETER sOutput_FuseValues; - - uint32_t ul_RO_fused, ul_CACb_fused, ul_CACm_fused, ul_Kt_Beta_fused, ul_= Kv_m_fused, ul_Kv_b_fused; - fInt fSM_A0, fSM_A1, fSM_A2, fSM_A3, fSM_A4, fSM_A5, fSM_A6, fSM_A7; - fInt fMargin_RO_a, fMargin_RO_b, fMargin_RO_c, fMargin_fixed, fMargin_FMA= X_mean, fMargin_Plat_mean, fMargin_FMAX_sigma, fMargin_Plat_sigma, fMargin_= DC_sigma; - fInt fLkg_FT, repeat; - fInt fMicro_FMAX, fMicro_CR, fSigma_FMAX, fSigma_CR, fSigma_DC, fDC_SCLK,= fSquared_Sigma_DC, fSquared_Sigma_CR, fSquared_Sigma_FMAX; - fInt fRLL_LoadLine, fDerateTDP, fVDDC_base, fA_Term, fC_Term, fB_Term, fR= O_DC_margin; - fInt fRO_fused, fCACm_fused, fCACb_fused, fKv_m_fused, fKv_b_fused, fKt_B= eta_fused, fFT_Lkg_V0NORM; - fInt fSclk_margin, fSclk, fEVV_V; - fInt fV_min, fV_max, fT_prod, fLKG_Factor, fT_FT, fV_FT, fV_x, fTDP_Power= , fTDP_Power_right, fTDP_Power_left, fTDP_Current, fV_NL; - uint32_t ul_FT_Lkg_V0NORM; - fInt fLn_MaxDivMin, fMin, fAverage, fRange; - fInt fRoots[2]; - fInt fStepSize =3D GetScaledFraction(625, 100000); - - int result; - - getASICProfilingInfo =3D (ATOM_ASIC_PROFILING_INFO_V3_4 *) - smu_atom_get_data_table(hwmgr->adev, - GetIndexIntoMasterTable(DATA, ASIC_ProfilingInfo), - NULL, NULL, NULL); - - if (!getASICProfilingInfo) - return -1; - - if (getASICProfilingInfo->asHeader.ucTableFormatRevision < 3 || - (getASICProfilingInfo->asHeader.ucTableFormatRevision =3D=3D 3 && - getASICProfilingInfo->asHeader.ucTableContentRevision < 4)) - return -1; - - /*----------------------------------------------------------- - *GETTING MULTI-STEP PARAMETERS RELATED TO CURRENT DPM LEVEL - *----------------------------------------------------------- - */ - fRLL_LoadLine =3D Divide(getASICProfilingInfo->ulLoadLineSlop, 1000); - - switch (dpm_level) { - case 1: - fDerateTDP =3D GetScaledFraction(le32_to_cpu(getASICProfilingInfo->ulTdp= DerateDPM1), 1000); - break; - case 2: - fDerateTDP =3D GetScaledFraction(le32_to_cpu(getASICProfilingInfo->ulTdp= DerateDPM2), 1000); - break; - case 3: - fDerateTDP =3D GetScaledFraction(le32_to_cpu(getASICProfilingInfo->ulTdp= DerateDPM3), 1000); - break; - case 4: - fDerateTDP =3D GetScaledFraction(le32_to_cpu(getASICProfilingInfo->ulTdp= DerateDPM4), 1000); - break; - case 5: - fDerateTDP =3D GetScaledFraction(le32_to_cpu(getASICProfilingInfo->ulTdp= DerateDPM5), 1000); - break; - case 6: - fDerateTDP =3D GetScaledFraction(le32_to_cpu(getASICProfilingInfo->ulTdp= DerateDPM6), 1000); - break; - case 7: - fDerateTDP =3D GetScaledFraction(le32_to_cpu(getASICProfilingInfo->ulTdp= DerateDPM7), 1000); - break; - default: - pr_err("DPM Level not supported\n"); - fDerateTDP =3D GetScaledFraction(le32_to_cpu(getASICProfilingInfo->ulTdp= DerateDPM0), 1000); - } - - /*------------------------- - * DECODING FUSE VALUES - * ------------------------ - */ - /*Decode RO_Fused*/ - sRO_fuse =3D getASICProfilingInfo->sRoFuse; - - sInput_FuseValues.usEfuseIndex =3D sRO_fuse.usEfuseIndex; - sInput_FuseValues.ucBitShift =3D sRO_fuse.ucEfuseBitLSB; - sInput_FuseValues.ucBitLength =3D sRO_fuse.ucEfuseLength; - - sOutput_FuseValues.sEfuse =3D sInput_FuseValues; - - result =3D amdgpu_atom_execute_table(adev->mode_info.atom_context, - GetIndexIntoMasterTable(COMMAND, ReadEfuseValue), - (uint32_t *)&sOutput_FuseValues, sizeof(sOutput_FuseValues)); - - if (result) - return result; - - /* Finally, the actual fuse value */ - ul_RO_fused =3D le32_to_cpu(sOutput_FuseValues.ulEfuseValue); - fMin =3D GetScaledFraction(le32_to_cpu(sRO_fuse.ulEfuseMin), 1); - fRange =3D GetScaledFraction(le32_to_cpu(sRO_fuse.ulEfuseEncodeRange), 1); - fRO_fused =3D fDecodeLinearFuse(ul_RO_fused, fMin, fRange, sRO_fuse.ucEfu= seLength); - - sCACm_fuse =3D getASICProfilingInfo->sCACm; - - sInput_FuseValues.usEfuseIndex =3D sCACm_fuse.usEfuseIndex; - sInput_FuseValues.ucBitShift =3D sCACm_fuse.ucEfuseBitLSB; - sInput_FuseValues.ucBitLength =3D sCACm_fuse.ucEfuseLength; - - sOutput_FuseValues.sEfuse =3D sInput_FuseValues; - - result =3D amdgpu_atom_execute_table(adev->mode_info.atom_context, - GetIndexIntoMasterTable(COMMAND, ReadEfuseValue), - (uint32_t *)&sOutput_FuseValues, sizeof(sOutput_FuseValues)); - - if (result) - return result; - - ul_CACm_fused =3D le32_to_cpu(sOutput_FuseValues.ulEfuseValue); - fMin =3D GetScaledFraction(le32_to_cpu(sCACm_fuse.ulEfuseMin), 1000); - fRange =3D GetScaledFraction(le32_to_cpu(sCACm_fuse.ulEfuseEncodeRange), = 1000); - - fCACm_fused =3D fDecodeLinearFuse(ul_CACm_fused, fMin, fRange, sCACm_fuse= .ucEfuseLength); - - sCACb_fuse =3D getASICProfilingInfo->sCACb; - - sInput_FuseValues.usEfuseIndex =3D sCACb_fuse.usEfuseIndex; - sInput_FuseValues.ucBitShift =3D sCACb_fuse.ucEfuseBitLSB; - sInput_FuseValues.ucBitLength =3D sCACb_fuse.ucEfuseLength; - sOutput_FuseValues.sEfuse =3D sInput_FuseValues; - - result =3D amdgpu_atom_execute_table(adev->mode_info.atom_context, - GetIndexIntoMasterTable(COMMAND, ReadEfuseValue), - (uint32_t *)&sOutput_FuseValues, sizeof(sOutput_FuseValues)); - - if (result) - return result; - - ul_CACb_fused =3D le32_to_cpu(sOutput_FuseValues.ulEfuseValue); - fMin =3D GetScaledFraction(le32_to_cpu(sCACb_fuse.ulEfuseMin), 1000); - fRange =3D GetScaledFraction(le32_to_cpu(sCACb_fuse.ulEfuseEncodeRange), = 1000); - - fCACb_fused =3D fDecodeLinearFuse(ul_CACb_fused, fMin, fRange, sCACb_fuse= .ucEfuseLength); - - sKt_Beta_fuse =3D getASICProfilingInfo->sKt_b; - - sInput_FuseValues.usEfuseIndex =3D sKt_Beta_fuse.usEfuseIndex; - sInput_FuseValues.ucBitShift =3D sKt_Beta_fuse.ucEfuseBitLSB; - sInput_FuseValues.ucBitLength =3D sKt_Beta_fuse.ucEfuseLength; - - sOutput_FuseValues.sEfuse =3D sInput_FuseValues; - - result =3D amdgpu_atom_execute_table(adev->mode_info.atom_context, - GetIndexIntoMasterTable(COMMAND, ReadEfuseValue), - (uint32_t *)&sOutput_FuseValues, sizeof(sOutput_FuseValues)); - - if (result) - return result; - - ul_Kt_Beta_fused =3D le32_to_cpu(sOutput_FuseValues.ulEfuseValue); - fAverage =3D GetScaledFraction(le32_to_cpu(sKt_Beta_fuse.ulEfuseEncodeAve= rage), 1000); - fRange =3D GetScaledFraction(le32_to_cpu(sKt_Beta_fuse.ulEfuseEncodeRange= ), 1000); - - fKt_Beta_fused =3D fDecodeLogisticFuse(ul_Kt_Beta_fused, - fAverage, fRange, sKt_Beta_fuse.ucEfuseLength); - - sKv_m_fuse =3D getASICProfilingInfo->sKv_m; - - sInput_FuseValues.usEfuseIndex =3D sKv_m_fuse.usEfuseIndex; - sInput_FuseValues.ucBitShift =3D sKv_m_fuse.ucEfuseBitLSB; - sInput_FuseValues.ucBitLength =3D sKv_m_fuse.ucEfuseLength; - - sOutput_FuseValues.sEfuse =3D sInput_FuseValues; - - result =3D amdgpu_atom_execute_table(adev->mode_info.atom_context, - GetIndexIntoMasterTable(COMMAND, ReadEfuseValue), - (uint32_t *)&sOutput_FuseValues, sizeof(sOutput_FuseValues)); - if (result) - return result; - - ul_Kv_m_fused =3D le32_to_cpu(sOutput_FuseValues.ulEfuseValue); - fAverage =3D GetScaledFraction(le32_to_cpu(sKv_m_fuse.ulEfuseEncodeAverag= e), 1000); - fRange =3D GetScaledFraction((le32_to_cpu(sKv_m_fuse.ulEfuseEncodeRange) = & 0x7fffffff), 1000); - fRange =3D fMultiply(fRange, ConvertToFraction(-1)); - - fKv_m_fused =3D fDecodeLogisticFuse(ul_Kv_m_fused, - fAverage, fRange, sKv_m_fuse.ucEfuseLength); - - sKv_b_fuse =3D getASICProfilingInfo->sKv_b; - - sInput_FuseValues.usEfuseIndex =3D sKv_b_fuse.usEfuseIndex; - sInput_FuseValues.ucBitShift =3D sKv_b_fuse.ucEfuseBitLSB; - sInput_FuseValues.ucBitLength =3D sKv_b_fuse.ucEfuseLength; - sOutput_FuseValues.sEfuse =3D sInput_FuseValues; - - result =3D amdgpu_atom_execute_table(adev->mode_info.atom_context, - GetIndexIntoMasterTable(COMMAND, ReadEfuseValue), - (uint32_t *)&sOutput_FuseValues, sizeof(sOutput_FuseValues)); - - if (result) - return result; - - ul_Kv_b_fused =3D le32_to_cpu(sOutput_FuseValues.ulEfuseValue); - fAverage =3D GetScaledFraction(le32_to_cpu(sKv_b_fuse.ulEfuseEncodeAverag= e), 1000); - fRange =3D GetScaledFraction(le32_to_cpu(sKv_b_fuse.ulEfuseEncodeRange), = 1000); - - fKv_b_fused =3D fDecodeLogisticFuse(ul_Kv_b_fused, - fAverage, fRange, sKv_b_fuse.ucEfuseLength); - - /* Decoding the Leakage - No special struct container */ - /* - * usLkgEuseIndex=3D56 - * ucLkgEfuseBitLSB=3D6 - * ucLkgEfuseLength=3D10 - * ulLkgEncodeLn_MaxDivMin=3D69077 - * ulLkgEncodeMax=3D1000000 - * ulLkgEncodeMin=3D1000 - * ulEfuseLogisticAlpha=3D13 - */ - - sInput_FuseValues.usEfuseIndex =3D getASICProfilingInfo->usLkgEuseIndex; - sInput_FuseValues.ucBitShift =3D getASICProfilingInfo->ucLkgEfuseBitLSB; - sInput_FuseValues.ucBitLength =3D getASICProfilingInfo->ucLkgEfuseLength; - - sOutput_FuseValues.sEfuse =3D sInput_FuseValues; - - result =3D amdgpu_atom_execute_table(adev->mode_info.atom_context, - GetIndexIntoMasterTable(COMMAND, ReadEfuseValue), - (uint32_t *)&sOutput_FuseValues, sizeof(sOutput_FuseValues)); - - if (result) - return result; - - ul_FT_Lkg_V0NORM =3D le32_to_cpu(sOutput_FuseValues.ulEfuseValue); - fLn_MaxDivMin =3D GetScaledFraction(le32_to_cpu(getASICProfilingInfo->ulL= kgEncodeLn_MaxDivMin), 10000); - fMin =3D GetScaledFraction(le32_to_cpu(getASICProfilingInfo->ulLkgEncodeM= in), 10000); - - fFT_Lkg_V0NORM =3D fDecodeLeakageID(ul_FT_Lkg_V0NORM, - fLn_MaxDivMin, fMin, getASICProfilingInfo->ucLkgEfuseLength); - fLkg_FT =3D fFT_Lkg_V0NORM; - - /*------------------------------------------- - * PART 2 - Grabbing all required values - *------------------------------------------- - */ - fSM_A0 =3D fMultiply(GetScaledFraction(le32_to_cpu(getASICProfilingInfo->= ulSM_A0), 1000000), - ConvertToFraction(uPow(-1, getASICProfilingInfo->ucSM_A0_sign))); - fSM_A1 =3D fMultiply(GetScaledFraction(le32_to_cpu(getASICProfilingInfo->= ulSM_A1), 1000000), - ConvertToFraction(uPow(-1, getASICProfilingInfo->ucSM_A1_sign))); - fSM_A2 =3D fMultiply(GetScaledFraction(le32_to_cpu(getASICProfilingInfo->= ulSM_A2), 100000), - ConvertToFraction(uPow(-1, getASICProfilingInfo->ucSM_A2_sign))); - fSM_A3 =3D fMultiply(GetScaledFraction(le32_to_cpu(getASICProfilingInfo->= ulSM_A3), 1000000), - ConvertToFraction(uPow(-1, getASICProfilingInfo->ucSM_A3_sign))); - fSM_A4 =3D fMultiply(GetScaledFraction(le32_to_cpu(getASICProfilingInfo->= ulSM_A4), 1000000), - ConvertToFraction(uPow(-1, getASICProfilingInfo->ucSM_A4_sign))); - fSM_A5 =3D fMultiply(GetScaledFraction(le32_to_cpu(getASICProfilingInfo->= ulSM_A5), 1000), - ConvertToFraction(uPow(-1, getASICProfilingInfo->ucSM_A5_sign))); - fSM_A6 =3D fMultiply(GetScaledFraction(le32_to_cpu(getASICProfilingInfo->= ulSM_A6), 1000), - ConvertToFraction(uPow(-1, getASICProfilingInfo->ucSM_A6_sign))); - fSM_A7 =3D fMultiply(GetScaledFraction(le32_to_cpu(getASICProfilingInfo->= ulSM_A7), 1000), - ConvertToFraction(uPow(-1, getASICProfilingInfo->ucSM_A7_sign))); - - fMargin_RO_a =3D ConvertToFraction(le32_to_cpu(getASICProfilingInfo->ulMa= rgin_RO_a)); - fMargin_RO_b =3D ConvertToFraction(le32_to_cpu(getASICProfilingInfo->ulMa= rgin_RO_b)); - fMargin_RO_c =3D ConvertToFraction(le32_to_cpu(getASICProfilingInfo->ulMa= rgin_RO_c)); - - fMargin_fixed =3D ConvertToFraction(le32_to_cpu(getASICProfilingInfo->ulM= argin_fixed)); - - fMargin_FMAX_mean =3D GetScaledFraction( - le32_to_cpu(getASICProfilingInfo->ulMargin_Fmax_mean), 10000); - fMargin_Plat_mean =3D GetScaledFraction( - le32_to_cpu(getASICProfilingInfo->ulMargin_plat_mean), 10000); - fMargin_FMAX_sigma =3D GetScaledFraction( - le32_to_cpu(getASICProfilingInfo->ulMargin_Fmax_sigma), 10000); - fMargin_Plat_sigma =3D GetScaledFraction( - le32_to_cpu(getASICProfilingInfo->ulMargin_plat_sigma), 10000); - - fMargin_DC_sigma =3D GetScaledFraction( - le32_to_cpu(getASICProfilingInfo->ulMargin_DC_sigma), 100); - fMargin_DC_sigma =3D fDivide(fMargin_DC_sigma, ConvertToFraction(1000)); - - fCACm_fused =3D fDivide(fCACm_fused, ConvertToFraction(100)); - fCACb_fused =3D fDivide(fCACb_fused, ConvertToFraction(100)); - fKt_Beta_fused =3D fDivide(fKt_Beta_fused, ConvertToFraction(100)); - fKv_m_fused =3D fNegate(fDivide(fKv_m_fused, ConvertToFraction(100))); - fKv_b_fused =3D fDivide(fKv_b_fused, ConvertToFraction(10)); - - fSclk =3D GetScaledFraction(sclk, 100); - - fV_max =3D fDivide(GetScaledFraction( - le32_to_cpu(getASICProfilingInfo->ulMaxVddc), 1000), ConvertToFractio= n(4)); - fT_prod =3D GetScaledFraction(le32_to_cpu(getASICProfilingInfo->ulBoardCo= reTemp), 10); - fLKG_Factor =3D GetScaledFraction(le32_to_cpu(getASICProfilingInfo->ulEvv= LkgFactor), 100); - fT_FT =3D GetScaledFraction(le32_to_cpu(getASICProfilingInfo->ulLeakageTe= mp), 10); - fV_FT =3D fDivide(GetScaledFraction( - le32_to_cpu(getASICProfilingInfo->ulLeakageVoltage), 1000), ConvertToF= raction(4)); - fV_min =3D fDivide(GetScaledFraction( - le32_to_cpu(getASICProfilingInfo->ulMinVddc), 1000), ConvertToFractio= n(4)); - - /*----------------------- - * PART 3 - *----------------------- - */ - - fA_Term =3D fAdd(fMargin_RO_a, fAdd(fMultiply(fSM_A4, fSclk), fSM_A5)); - fB_Term =3D fAdd(fAdd(fMultiply(fSM_A2, fSclk), fSM_A6), fMargin_RO_b); - fC_Term =3D fAdd(fMargin_RO_c, - fAdd(fMultiply(fSM_A0, fLkg_FT), - fAdd(fMultiply(fSM_A1, fMultiply(fLkg_FT, fSclk)), - fAdd(fMultiply(fSM_A3, fSclk), - fSubtract(fSM_A7, fRO_fused))))); - - fVDDC_base =3D fSubtract(fRO_fused, - fSubtract(fMargin_RO_c, - fSubtract(fSM_A3, fMultiply(fSM_A1, fSclk)))); - fVDDC_base =3D fDivide(fVDDC_base, fAdd(fMultiply(fSM_A0, fSclk), fSM_A2)= ); - - repeat =3D fSubtract(fVDDC_base, - fDivide(fMargin_DC_sigma, ConvertToFraction(1000))); - - fRO_DC_margin =3D fAdd(fMultiply(fMargin_RO_a, - fGetSquare(repeat)), - fAdd(fMultiply(fMargin_RO_b, repeat), - fMargin_RO_c)); - - fDC_SCLK =3D fSubtract(fRO_fused, - fSubtract(fRO_DC_margin, - fSubtract(fSM_A3, - fMultiply(fSM_A2, repeat)))); - fDC_SCLK =3D fDivide(fDC_SCLK, fAdd(fMultiply(fSM_A0, repeat), fSM_A1)); - - fSigma_DC =3D fSubtract(fSclk, fDC_SCLK); - - fMicro_FMAX =3D fMultiply(fSclk, fMargin_FMAX_mean); - fMicro_CR =3D fMultiply(fSclk, fMargin_Plat_mean); - fSigma_FMAX =3D fMultiply(fSclk, fMargin_FMAX_sigma); - fSigma_CR =3D fMultiply(fSclk, fMargin_Plat_sigma); - - fSquared_Sigma_DC =3D fGetSquare(fSigma_DC); - fSquared_Sigma_CR =3D fGetSquare(fSigma_CR); - fSquared_Sigma_FMAX =3D fGetSquare(fSigma_FMAX); - - fSclk_margin =3D fAdd(fMicro_FMAX, - fAdd(fMicro_CR, - fAdd(fMargin_fixed, - fSqrt(fAdd(fSquared_Sigma_FMAX, - fAdd(fSquared_Sigma_DC, fSquared_Sigma_CR)))))); - /* - fA_Term =3D fSM_A4 * (fSclk + fSclk_margin) + fSM_A5; - fB_Term =3D fSM_A2 * (fSclk + fSclk_margin) + fSM_A6; - fC_Term =3D fRO_DC_margin + fSM_A0 * fLkg_FT + fSM_A1 * fLkg_FT * (fSclk= + fSclk_margin) + fSM_A3 * (fSclk + fSclk_margin) + fSM_A7 - fRO_fused; - */ - - fA_Term =3D fAdd(fMultiply(fSM_A4, fAdd(fSclk, fSclk_margin)), fSM_A5); - fB_Term =3D fAdd(fMultiply(fSM_A2, fAdd(fSclk, fSclk_margin)), fSM_A6); - fC_Term =3D fAdd(fRO_DC_margin, - fAdd(fMultiply(fSM_A0, fLkg_FT), - fAdd(fMultiply(fMultiply(fSM_A1, fLkg_FT), - fAdd(fSclk, fSclk_margin)), - fAdd(fMultiply(fSM_A3, - fAdd(fSclk, fSclk_margin)), - fSubtract(fSM_A7, fRO_fused))))); - - SolveQuadracticEqn(fA_Term, fB_Term, fC_Term, fRoots); - - if (GreaterThan(fRoots[0], fRoots[1])) - fEVV_V =3D fRoots[1]; - else - fEVV_V =3D fRoots[0]; - - if (GreaterThan(fV_min, fEVV_V)) - fEVV_V =3D fV_min; - else if (GreaterThan(fEVV_V, fV_max)) - fEVV_V =3D fSubtract(fV_max, fStepSize); - - fEVV_V =3D fRoundUpByStepSize(fEVV_V, fStepSize, 0); - - /*----------------- - * PART 4 - *----------------- - */ - - fV_x =3D fV_min; - - while (GreaterThan(fAdd(fV_max, fStepSize), fV_x)) { - fTDP_Power_left =3D fMultiply(fMultiply(fMultiply(fAdd( - fMultiply(fCACm_fused, fV_x), fCACb_fused), fSclk), - fGetSquare(fV_x)), fDerateTDP); - - fTDP_Power_right =3D fMultiply(fFT_Lkg_V0NORM, fMultiply(fLKG_Factor, - fMultiply(fExponential(fMultiply(fAdd(fMultiply(fKv_m_fused, - fT_prod), fKv_b_fused), fV_x)), fV_x))); - fTDP_Power_right =3D fMultiply(fTDP_Power_right, fExponential(fMultiply( - fKt_Beta_fused, fT_prod))); - fTDP_Power_right =3D fDivide(fTDP_Power_right, fExponential(fMultiply( - fAdd(fMultiply(fKv_m_fused, fT_prod), fKv_b_fused), fV_FT))); - fTDP_Power_right =3D fDivide(fTDP_Power_right, fExponential(fMultiply( - fKt_Beta_fused, fT_FT))); - - fTDP_Power =3D fAdd(fTDP_Power_left, fTDP_Power_right); - - fTDP_Current =3D fDivide(fTDP_Power, fV_x); - - fV_NL =3D fAdd(fV_x, fDivide(fMultiply(fTDP_Current, fRLL_LoadLine), - ConvertToFraction(10))); - - fV_NL =3D fRoundUpByStepSize(fV_NL, fStepSize, 0); - - if (GreaterThan(fV_max, fV_NL) && - (GreaterThan(fV_NL, fEVV_V) || - Equal(fV_NL, fEVV_V))) { - fV_NL =3D fMultiply(fV_NL, ConvertToFraction(1000)); - - *voltage =3D (uint16_t)fV_NL.partial.real; - break; - } else - fV_x =3D fAdd(fV_x, fStepSize); - } - - return result; -} - /** * atomctrl_get_voltage_evv_on_sclk: gets voltage via call to ATOM COMMAND= table. * @hwmgr: input: pointer to hwManager diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.h b/drivers/= gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.h index 1f987e846628..22b0ac12df97 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.h +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppatomctrl.h @@ -316,8 +316,6 @@ extern int atomctrl_get_engine_pll_dividers_kong(struct= pp_hwmgr *hwmgr, pp_atomctrl_clock_dividers_kong *dividers); extern int atomctrl_read_efuse(struct pp_hwmgr *hwmgr, uint16_t start_inde= x, uint16_t end_index, uint32_t *efuse); -extern int atomctrl_calculate_voltage_evv_on_sclk(struct pp_hwmgr *hwmgr, = uint8_t voltage_type, - uint32_t sclk, uint16_t virtual_voltage_Id, uint16_t *voltage, uint16_t = dpm_level, bool debug); extern int atomctrl_get_engine_pll_dividers_ai(struct pp_hwmgr *hwmgr, uin= t32_t clock_value, pp_atomctrl_clock_dividers_ai *dividers); extern int atomctrl_set_ac_timing_ai(struct pp_hwmgr *hwmgr, uint32_t memo= ry_clock, uint8_t level); diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppevvmath.h b/drivers/g= pu/drm/amd/pm/powerplay/hwmgr/ppevvmath.h deleted file mode 100644 index 409aeec6baa9..000000000000 --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/ppevvmath.h +++ /dev/null @@ -1,561 +0,0 @@ -/* - * Copyright 2015 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software= "), - * to deal in the Software without restriction, including without limitati= on - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - */ -#include - -enum ppevvmath_constants { - /* We multiply all original integers with 2^SHIFT_AMOUNT to get the fInt = representation */ - SHIFT_AMOUNT =3D 16, - - /* Change this value to change the number of decimal places in the final = output - 5 is a good default */ - PRECISION =3D 5, - - SHIFTED_2 =3D (2 << SHIFT_AMOUNT), - - /* 32767 - Might change in the future */ - MAX =3D (1 << (SHIFT_AMOUNT - 1)) - 1, -}; - -/* -----------------------------------------------------------------------= -------- - * NEW TYPE - fINT - * -----------------------------------------------------------------------= -------- - * A variable of type fInt can be accessed in 3 ways using the dot (.) ope= rator - * fInt A; - * A.full =3D> The full number as it is. Generally not easy to read - * A.partial.real =3D> Only the integer portion - * A.partial.decimal =3D> Only the fractional portion - */ -typedef union _fInt { - int full; - struct _partial { - unsigned int decimal: SHIFT_AMOUNT; /*Needs to always be unsigned*/ - int real: 32 - SHIFT_AMOUNT; - } partial; -} fInt; - -/* -----------------------------------------------------------------------= -------- - * Function Declarations - * ----------------------------------------------------------------------= --------- - */ -static fInt ConvertToFraction(int); /* Use this to c= onvert an INT to a FINT */ -static fInt Convert_ULONG_ToFraction(uint32_t); /* Use this to c= onvert an uint32_t to a FINT */ -static fInt GetScaledFraction(int, int); /* Use this to c= onvert an INT to a FINT after scaling it by a factor */ -static int ConvertBackToInteger(fInt); /* Convert a FIN= T back to an INT that is scaled by 1000 (i.e. last 3 digits are the decimal= digits) */ - -static fInt fNegate(fInt); /* Returns -1 * = input fInt value */ -static fInt fAdd (fInt, fInt); /* Returns the s= um of two fInt numbers */ -static fInt fSubtract (fInt A, fInt B); /* Returns A-B -= Sometimes easier than Adding negative numbers */ -static fInt fMultiply (fInt, fInt); /* Returns the p= roduct of two fInt numbers */ -static fInt fDivide (fInt A, fInt B); /* Returns A/B */ -static fInt fGetSquare(fInt); /* Returns the s= quare of a fInt number */ -static fInt fSqrt(fInt); /* Returns the S= quare Root of a fInt number */ - -static int uAbs(int); /* Returns the A= bsolute value of the Int */ -static int uPow(int base, int exponent); /* Returns base^= exponent an INT */ - -static void SolveQuadracticEqn(fInt, fInt, fInt, fInt[]); /* Returns the 2= roots via the array */ -static bool Equal(fInt, fInt); /* Returns true = if two fInts are equal to each other */ -static bool GreaterThan(fInt A, fInt B); /* Returns true = if A > B */ - -static fInt fExponential(fInt exponent); /* Can be used t= o calculate e^exponent */ -static fInt fNaturalLog(fInt value); /* Can be used t= o calculate ln(value) */ - -/* Fuse decoding functions - * -----------------------------------------------------------------------= -------------- - */ -static fInt fDecodeLinearFuse(uint32_t fuse_value, fInt f_min, fInt f_rang= e, uint32_t bitlength); -static fInt fDecodeLogisticFuse(uint32_t fuse_value, fInt f_average, fInt = f_range, uint32_t bitlength); -static fInt fDecodeLeakageID (uint32_t leakageID_fuse, fInt ln_max_div_min= , fInt f_min, uint32_t bitlength); - -/* Internal Support Functions - Use these ONLY for testing or adding to in= ternal functions - * -----------------------------------------------------------------------= -------------- - * Some of the following functions take two INTs as their input - This is = unsafe for a variety of reasons. - */ -static fInt Divide (int, int); /* Divide two IN= Ts and return result as FINT */ -static fInt fNegate(fInt); - -static int uGetScaledDecimal (fInt); /* Internal func= tion */ -static int GetReal (fInt A); /* Internal func= tion */ - -/* -----------------------------------------------------------------------= -------------- - * TROUBLESHOOTING INFORMATION - * -----------------------------------------------------------------------= -------------- - * 1) ConvertToFraction - InputOutOfRangeException: Only accepts numbers s= maller than MAX (default: 32767) - * 2) fAdd - OutputOutOfRangeException: Output bigger than MAX (default: 3= 2767) - * 3) fMultiply - OutputOutOfRangeException: - * 4) fGetSquare - OutputOutOfRangeException: - * 5) fDivide - DivideByZeroException - * 6) fSqrt - NegativeSquareRootException: Input cannot be a negative numb= er - */ - -/* -----------------------------------------------------------------------= -------------- - * START OF CODE - * -----------------------------------------------------------------------= -------------- - */ -static fInt fExponential(fInt exponent) /*Can be used to calculate = e^exponent*/ -{ - uint32_t i; - bool bNegated =3D false; - - fInt fPositiveOne =3D ConvertToFraction(1); - fInt fZERO =3D ConvertToFraction(0); - - fInt lower_bound =3D Divide(78, 10000); - fInt solution =3D fPositiveOne; /*Starting off with baseline of 1 */ - fInt error_term; - - static const uint32_t k_array[11] =3D {55452, 27726, 13863, 6931, 4055, 2= 231, 1178, 606, 308, 155, 78}; - static const uint32_t expk_array[11] =3D {2560000, 160000, 40000, 20000, = 15000, 12500, 11250, 10625, 10313, 10156, 10078}; - - if (GreaterThan(fZERO, exponent)) { - exponent =3D fNegate(exponent); - bNegated =3D true; - } - - while (GreaterThan(exponent, lower_bound)) { - for (i =3D 0; i < 11; i++) { - if (GreaterThan(exponent, GetScaledFraction(k_array[i], 10000))) { - exponent =3D fSubtract(exponent, GetScaledFraction(k_array[i], 10000)); - solution =3D fMultiply(solution, GetScaledFraction(expk_array[i], 1000= 0)); - } - } - } - - error_term =3D fAdd(fPositiveOne, exponent); - - solution =3D fMultiply(solution, error_term); - - if (bNegated) - solution =3D fDivide(fPositiveOne, solution); - - return solution; -} - -static fInt fNaturalLog(fInt value) -{ - uint32_t i; - fInt upper_bound =3D Divide(8, 1000); - fInt fNegativeOne =3D ConvertToFraction(-1); - fInt solution =3D ConvertToFraction(0); /*Starting off with baseline of 0= */ - fInt error_term; - - static const uint32_t k_array[10] =3D {160000, 40000, 20000, 15000, 12500= , 11250, 10625, 10313, 10156, 10078}; - static const uint32_t logk_array[10] =3D {27726, 13863, 6931, 4055, 2231,= 1178, 606, 308, 155, 78}; - - while (GreaterThan(fAdd(value, fNegativeOne), upper_bound)) { - for (i =3D 0; i < 10; i++) { - if (GreaterThan(value, GetScaledFraction(k_array[i], 10000))) { - value =3D fDivide(value, GetScaledFraction(k_array[i], 10000)); - solution =3D fAdd(solution, GetScaledFraction(logk_array[i], 10000)); - } - } - } - - error_term =3D fAdd(fNegativeOne, value); - - return fAdd(solution, error_term); -} - -static fInt fDecodeLinearFuse(uint32_t fuse_value, fInt f_min, fInt f_rang= e, uint32_t bitlength) -{ - fInt f_fuse_value =3D Convert_ULONG_ToFraction(fuse_value); - fInt f_bit_max_value =3D Convert_ULONG_ToFraction((uPow(2, bitlength)) - = 1); - - fInt f_decoded_value; - - f_decoded_value =3D fDivide(f_fuse_value, f_bit_max_value); - f_decoded_value =3D fMultiply(f_decoded_value, f_range); - f_decoded_value =3D fAdd(f_decoded_value, f_min); - - return f_decoded_value; -} - - -static fInt fDecodeLogisticFuse(uint32_t fuse_value, fInt f_average, fInt = f_range, uint32_t bitlength) -{ - fInt f_fuse_value =3D Convert_ULONG_ToFraction(fuse_value); - fInt f_bit_max_value =3D Convert_ULONG_ToFraction((uPow(2, bitlength)) - = 1); - - fInt f_CONSTANT_NEG13 =3D ConvertToFraction(-13); - fInt f_CONSTANT1 =3D ConvertToFraction(1); - - fInt f_decoded_value; - - f_decoded_value =3D fSubtract(fDivide(f_bit_max_value, f_fuse_value), f_C= ONSTANT1); - f_decoded_value =3D fNaturalLog(f_decoded_value); - f_decoded_value =3D fMultiply(f_decoded_value, fDivide(f_range, f_CONSTAN= T_NEG13)); - f_decoded_value =3D fAdd(f_decoded_value, f_average); - - return f_decoded_value; -} - -static fInt fDecodeLeakageID (uint32_t leakageID_fuse, fInt ln_max_div_min= , fInt f_min, uint32_t bitlength) -{ - fInt fLeakage; - fInt f_bit_max_value =3D Convert_ULONG_ToFraction((uPow(2, bitlength)) - = 1); - - fLeakage =3D fMultiply(ln_max_div_min, Convert_ULONG_ToFraction(leakageID= _fuse)); - fLeakage =3D fDivide(fLeakage, f_bit_max_value); - fLeakage =3D fExponential(fLeakage); - fLeakage =3D fMultiply(fLeakage, f_min); - - return fLeakage; -} - -static fInt ConvertToFraction(int X) /*Add all range checking here. Is it = possible to make fInt a private declaration? */ -{ - fInt temp; - - if (X <=3D MAX) - temp.full =3D (X << SHIFT_AMOUNT); - else - temp.full =3D 0; - - return temp; -} - -static fInt fNegate(fInt X) -{ - fInt CONSTANT_NEGONE =3D ConvertToFraction(-1); - return fMultiply(X, CONSTANT_NEGONE); -} - -static fInt Convert_ULONG_ToFraction(uint32_t X) -{ - fInt temp; - - if (X <=3D MAX) - temp.full =3D (X << SHIFT_AMOUNT); - else - temp.full =3D 0; - - return temp; -} - -static fInt GetScaledFraction(int X, int factor) -{ - int times_shifted, factor_shifted; - bool bNEGATED; - fInt fValue; - - times_shifted =3D 0; - factor_shifted =3D 0; - bNEGATED =3D false; - - if (X < 0) { - X =3D -1*X; - bNEGATED =3D true; - } - - if (factor < 0) { - factor =3D -1*factor; - bNEGATED =3D !bNEGATED; /*If bNEGATED =3D true due to X < 0, this will c= over the case of negative cancelling negative */ - } - - if ((X > MAX) || factor > MAX) { - if ((X/factor) <=3D MAX) { - while (X > MAX) { - X =3D X >> 1; - times_shifted++; - } - - while (factor > MAX) { - factor =3D factor >> 1; - factor_shifted++; - } - } else { - fValue.full =3D 0; - return fValue; - } - } - - if (factor =3D=3D 1) - return ConvertToFraction(X); - - fValue =3D fDivide(ConvertToFraction(X * uPow(-1, bNEGATED)), ConvertToFr= action(factor)); - - fValue.full =3D fValue.full << times_shifted; - fValue.full =3D fValue.full >> factor_shifted; - - return fValue; -} - -/* Addition using two fInts */ -static fInt fAdd (fInt X, fInt Y) -{ - fInt Sum; - - Sum.full =3D X.full + Y.full; - - return Sum; -} - -/* Addition using two fInts */ -static fInt fSubtract (fInt X, fInt Y) -{ - fInt Difference; - - Difference.full =3D X.full - Y.full; - - return Difference; -} - -static bool Equal(fInt A, fInt B) -{ - if (A.full =3D=3D B.full) - return true; - else - return false; -} - -static bool GreaterThan(fInt A, fInt B) -{ - if (A.full > B.full) - return true; - else - return false; -} - -static fInt fMultiply (fInt X, fInt Y) /* Uses 64-bit integers (int64_t) */ -{ - fInt Product; - int64_t tempProduct; - - /*The following is for a very specific common case: Non-zero number with = ONLY fractional portion*/ - /* TEMPORARILY DISABLED - CAN BE USED TO IMPROVE PRECISION - bool X_LessThanOne, Y_LessThanOne; - - X_LessThanOne =3D (X.partial.real =3D=3D 0 && X.partial.decimal !=3D 0 &&= X.full >=3D 0); - Y_LessThanOne =3D (Y.partial.real =3D=3D 0 && Y.partial.decimal !=3D 0 &&= Y.full >=3D 0); - - if (X_LessThanOne && Y_LessThanOne) { - Product.full =3D X.full * Y.full; - return Product - }*/ - - tempProduct =3D ((int64_t)X.full) * ((int64_t)Y.full); /*Q(16,16)*Q(16,16= ) =3D Q(32, 32) - Might become a negative number! */ - tempProduct =3D tempProduct >> 16; /*Remove lagging 16 bits - Will lose s= ome precision from decimal; */ - Product.full =3D (int)tempProduct; /*The int64_t will lose the leading 16= bits that were part of the integer portion */ - - return Product; -} - -static fInt fDivide (fInt X, fInt Y) -{ - fInt fZERO, fQuotient; - int64_t longlongX, longlongY; - - fZERO =3D ConvertToFraction(0); - - if (Equal(Y, fZERO)) - return fZERO; - - longlongX =3D (int64_t)X.full; - longlongY =3D (int64_t)Y.full; - - longlongX =3D longlongX << 16; /*Q(16,16) -> Q(32,32) */ - - div64_s64(longlongX, longlongY); /*Q(32,32) divided by Q(16,16) =3D Q(16,= 16) Back to original format */ - - fQuotient.full =3D (int)longlongX; - return fQuotient; -} - -static int ConvertBackToInteger (fInt A) /*THIS is the function that will = be used to check with the Golden settings table*/ -{ - fInt fullNumber, scaledDecimal, scaledReal; - - scaledReal.full =3D GetReal(A) * uPow(10, PRECISION-1); /* DOUBLE CHECK T= HISSSS!!! */ - - scaledDecimal.full =3D uGetScaledDecimal(A); - - fullNumber =3D fAdd(scaledDecimal, scaledReal); - - return fullNumber.full; -} - -static fInt fGetSquare(fInt A) -{ - return fMultiply(A, A); -} - -/* x_new =3D x_old - (x_old^2 - C) / (2 * x_old) */ -static fInt fSqrt(fInt num) -{ - fInt F_divide_Fprime, Fprime; - fInt test; - fInt twoShifted; - int seed, counter, error; - fInt x_new, x_old, C, y; - - fInt fZERO =3D ConvertToFraction(0); - - /* (0 > num) is the same as (num < 0), i.e., num is negative */ - - if (GreaterThan(fZERO, num) || Equal(fZERO, num)) - return fZERO; - - C =3D num; - - if (num.partial.real > 3000) - seed =3D 60; - else if (num.partial.real > 1000) - seed =3D 30; - else if (num.partial.real > 100) - seed =3D 10; - else - seed =3D 2; - - counter =3D 0; - - if (Equal(num, fZERO)) /*Square Root of Zero is zero */ - return fZERO; - - twoShifted =3D ConvertToFraction(2); - x_new =3D ConvertToFraction(seed); - - do { - counter++; - - x_old.full =3D x_new.full; - - test =3D fGetSquare(x_old); /*1.75*1.75 is reverting back to 1 when shif= ted down */ - y =3D fSubtract(test, C); /*y =3D f(x) =3D x^2 - C; */ - - Fprime =3D fMultiply(twoShifted, x_old); - F_divide_Fprime =3D fDivide(y, Fprime); - - x_new =3D fSubtract(x_old, F_divide_Fprime); - - error =3D ConvertBackToInteger(x_new) - ConvertBackToInteger(x_old); - - if (counter > 20) /*20 is already way too many iterations. If we dont ha= ve an answer by then, we never will*/ - return x_new; - - } while (uAbs(error) > 0); - - return x_new; -} - -static void SolveQuadracticEqn(fInt A, fInt B, fInt C, fInt Roots[]) -{ - fInt *pRoots =3D &Roots[0]; - fInt temp, root_first, root_second; - fInt f_CONSTANT10, f_CONSTANT100; - - f_CONSTANT100 =3D ConvertToFraction(100); - f_CONSTANT10 =3D ConvertToFraction(10); - - while (GreaterThan(A, f_CONSTANT100) || GreaterThan(B, f_CONSTANT100) || = GreaterThan(C, f_CONSTANT100)) { - A =3D fDivide(A, f_CONSTANT10); - B =3D fDivide(B, f_CONSTANT10); - C =3D fDivide(C, f_CONSTANT10); - } - - temp =3D fMultiply(ConvertToFraction(4), A); /* root =3D 4*A */ - temp =3D fMultiply(temp, C); /* root =3D 4*A*C */ - temp =3D fSubtract(fGetSquare(B), temp); /* root =3D b^2 - 4AC */ - temp =3D fSqrt(temp); /*root =3D Sqrt (b^2 - 4AC); */ - - root_first =3D fSubtract(fNegate(B), temp); /* b - Sqrt(b^2 - 4AC) */ - root_second =3D fAdd(fNegate(B), temp); /* b + Sqrt(b^2 - 4AC) */ - - root_first =3D fDivide(root_first, ConvertToFraction(2)); /* [b +- Sqrt(b= ^2 - 4AC)]/[2] */ - root_first =3D fDivide(root_first, A); /*[b +- Sqrt(b^2 - 4AC)]/[2*A] */ - - root_second =3D fDivide(root_second, ConvertToFraction(2)); /* [b +- Sqrt= (b^2 - 4AC)]/[2] */ - root_second =3D fDivide(root_second, A); /*[b +- Sqrt(b^2 - 4AC)]/[2*A] */ - - *(pRoots + 0) =3D root_first; - *(pRoots + 1) =3D root_second; -} - -/* -----------------------------------------------------------------------= ------ - * SUPPORT FUNCTIONS - * -----------------------------------------------------------------------= ------ - */ - -/* Conversion Functions */ -static int GetReal (fInt A) -{ - return (A.full >> SHIFT_AMOUNT); -} - -static fInt Divide (int X, int Y) -{ - fInt A, B, Quotient; - - A.full =3D X << SHIFT_AMOUNT; - B.full =3D Y << SHIFT_AMOUNT; - - Quotient =3D fDivide(A, B); - - return Quotient; -} - -static int uGetScaledDecimal (fInt A) /*Converts the fractional portion to= whole integers - Costly function */ -{ - int dec[PRECISION]; - int i, scaledDecimal =3D 0, tmp =3D A.partial.decimal; - - for (i =3D 0; i < PRECISION; i++) { - dec[i] =3D tmp / (1 << SHIFT_AMOUNT); - tmp =3D tmp - ((1 << SHIFT_AMOUNT)*dec[i]); - tmp *=3D 10; - scaledDecimal =3D scaledDecimal + dec[i]*uPow(10, PRECISION - 1 - i); - } - - return scaledDecimal; -} - -static int uPow(int base, int power) -{ - if (power =3D=3D 0) - return 1; - else - return (base)*uPow(base, power - 1); -} - -static int uAbs(int X) -{ - if (X < 0) - return (X * -1); - else - return X; -} - -static fInt fRoundUpByStepSize(fInt A, fInt fStepSize, bool error_term) -{ - fInt solution; - - solution =3D fDivide(A, fStepSize); - solution.partial.decimal =3D 0; /*All fractional digits changes to 0 */ - - if (error_term) - solution.partial.real +=3D 1; /*Error term of 1 added */ - - solution =3D fMultiply(solution, fStepSize); - solution =3D fAdd(solution, fStepSize); - - return solution; -} - --=20 2.46.2