/* * 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 limitation * 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 <asm/div64.h> enum ppevvmath_constants { … }; /* ------------------------------------------------------------------------------- * NEW TYPE - fINT * ------------------------------------------------------------------------------- * A variable of type fInt can be accessed in 3 ways using the dot (.) operator * fInt A; * A.full => The full number as it is. Generally not easy to read * A.partial.real => Only the integer portion * A.partial.decimal => Only the fractional portion */ fInt; /* ------------------------------------------------------------------------------- * Function Declarations * ------------------------------------------------------------------------------- */ static fInt ConvertToFraction(int); /* Use this to convert an INT to a FINT */ static fInt Convert_ULONG_ToFraction(uint32_t); /* Use this to convert an uint32_t to a FINT */ static fInt GetScaledFraction(int, int); /* Use this to convert an INT to a FINT after scaling it by a factor */ static int ConvertBackToInteger(fInt); /* Convert a FINT 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 sum 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 product of two fInt numbers */ static fInt fDivide (fInt A, fInt B); /* Returns A/B */ static fInt fGetSquare(fInt); /* Returns the square of a fInt number */ static fInt fSqrt(fInt); /* Returns the Square Root of a fInt number */ static int uAbs(int); /* Returns the Absolute 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 to calculate e^exponent */ static fInt fNaturalLog(fInt value); /* Can be used to calculate ln(value) */ /* Fuse decoding functions * ------------------------------------------------------------------------------------- */ static fInt fDecodeLinearFuse(uint32_t fuse_value, fInt f_min, fInt f_range, 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 internal 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 INTs and return result as FINT */ static fInt fNegate(fInt); static int uGetScaledDecimal (fInt); /* Internal function */ static int GetReal (fInt A); /* Internal function */ /* ------------------------------------------------------------------------------------- * TROUBLESHOOTING INFORMATION * ------------------------------------------------------------------------------------- * 1) ConvertToFraction - InputOutOfRangeException: Only accepts numbers smaller than MAX (default: 32767) * 2) fAdd - OutputOutOfRangeException: Output bigger than MAX (default: 32767) * 3) fMultiply - OutputOutOfRangeException: * 4) fGetSquare - OutputOutOfRangeException: * 5) fDivide - DivideByZeroException * 6) fSqrt - NegativeSquareRootException: Input cannot be a negative number */ /* ------------------------------------------------------------------------------------- * START OF CODE * ------------------------------------------------------------------------------------- */ static fInt fExponential(fInt exponent) /*Can be used to calculate e^exponent*/ { … } static fInt fNaturalLog(fInt value) { … } static fInt fDecodeLinearFuse(uint32_t fuse_value, fInt f_min, fInt f_range, 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) { … } static fInt ConvertToFraction(int X) /*Add all range checking here. Is it possible to make fInt a private declaration? */ { … } static fInt fNegate(fInt X) { … } static fInt Convert_ULONG_ToFraction(uint32_t X) { … } static fInt GetScaledFraction(int X, int factor) { … } /* Addition using two fInts */ static fInt fAdd (fInt X, fInt Y) { … } /* Addition using two fInts */ static fInt fSubtract (fInt X, fInt Y) { … } static bool Equal(fInt A, fInt B) { … } static bool GreaterThan(fInt A, fInt B) { … } static fInt fMultiply (fInt X, fInt Y) /* Uses 64-bit integers (int64_t) */ { … } static fInt fDivide (fInt X, fInt Y) { … } static int ConvertBackToInteger (fInt A) /*THIS is the function that will be used to check with the Golden settings table*/ { … } static fInt fGetSquare(fInt A) { … } /* x_new = x_old - (x_old^2 - C) / (2 * x_old) */ static fInt fSqrt(fInt num) { … } static void SolveQuadracticEqn(fInt A, fInt B, fInt C, fInt Roots[]) { … } /* ----------------------------------------------------------------------------- * SUPPORT FUNCTIONS * ----------------------------------------------------------------------------- */ /* Conversion Functions */ static int GetReal (fInt A) { … } static fInt Divide (int X, int Y) { … } static int uGetScaledDecimal (fInt A) /*Converts the fractional portion to whole integers - Costly function */ { … } static int uPow(int base, int power) { … } static int uAbs(int X) { … } static fInt fRoundUpByStepSize(fInt A, fInt fStepSize, bool error_term) { … }