亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? fastmath.cpp

?? NVIDIA 的數學運算庫,包括快速開方,浮點轉整數等
?? CPP
字號:
/*****************************************************************************
File:  fastmath.cpp

This file is provided without support, instruction, or implied warranty of any
kind.  NVIDIA makes no guarantee of its fitness for a particular purpose and is
not liable under any circumstances for any damages or loss whatsoever arising
from the use or inability to use this file or items derived from it.

Comments:


******************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <wtypes.h>


#define FP_BITS(fp) (*(DWORD *)&(fp))
#define FP_ABS_BITS(fp) (FP_BITS(fp)&0x7FFFFFFF)
#define FP_SIGN_BIT(fp) (FP_BITS(fp)&0x80000000)
#define FP_ONE_BITS 0x3F800000


// r = 1/p
#define FP_INV(r,p)                                                          \
{                                                                            \
    int _i = 2 * FP_ONE_BITS - *(int *)&(p);                                 \
    r = *(float *)&_i;                                                       \
    r = r * (2.0f - (p) * r);                                                \
}

/////////////////////////////////////////////////
// The following comes from Vincent Van Eeckhout
// Thanks for sending us the code!
// It's the same thing in assembly but without this C-needed line:
//    r = *(float *)&_i;

float   two = 2.0f;

#define FP_INV2(r,p)                     \
{                                        \
    __asm { mov     eax,0x7F000000    }; \
    __asm { sub     eax,dword ptr [p] }; \
    __asm { mov     dword ptr [r],eax }; \
    __asm { fld     dword ptr [p]     }; \
    __asm { fmul    dword ptr [r]     }; \
    __asm { fsubr   [two]             }; \
    __asm { fmul    dword ptr [r]     }; \
    __asm { fstp    dword ptr [r]     }; \
}

/////////////////////////////////////////////////


#define FP_EXP(e,p)                                                          \
{                                                                            \
    int _i;                                                                  \
    e = -1.44269504f * (float)0x00800000 * (p);                              \
    _i = (int)e + 0x3F800000;                                                \
    e = *(float *)&_i;                                                       \
}

#define FP_NORM_TO_BYTE(i,p)                                                 \
{                                                                            \
    float _n = (p) + 1.0f;                                                   \
    i = *(int *)&_n;                                                         \
    if (i >= 0x40000000)     i = 0xFF;                                       \
    else if (i <=0x3F800000) i = 0;                                          \
    else i = ((i) >> 15) & 0xFF;                                             \
}



inline unsigned long FP_NORM_TO_BYTE2(float p)                                                 
{                                                                            
  float fpTmp = p + 1.0f;                                                      
  return ((*(unsigned *)&fpTmp) >> 15) & 0xFF;  
}


inline unsigned long FP_NORM_TO_BYTE3(float p)     
{
  float ftmp = p + 12582912.0f;                                                      
  return ((*(unsigned long *)&ftmp) & 0xFF);
}



static unsigned int fast_sqrt_table[0x10000];  // declare table of square roots 

typedef union FastSqrtUnion
{
  float f;
  unsigned int i;
} FastSqrtUnion;

void  build_sqrt_table()
{
  unsigned int i;
  FastSqrtUnion s;
  
  for (i = 0; i <= 0x7FFF; i++)
  {
    
    // Build a float with the bit pattern i as mantissa
    //  and an exponent of 0, stored as 127
    
    s.i = (i << 8) | (0x7F << 23);
    s.f = (float)sqrt(s.f);
    
    // Take the square root then strip the first 7 bits of
    //  the mantissa into the table
    
    fast_sqrt_table[i + 0x8000] = (s.i & 0x7FFFFF);
    
    // Repeat the process, this time with an exponent of 1, 
    //  stored as 128
    
    s.i = (i << 8) | (0x80 << 23);
    s.f = (float)sqrt(s.f);
    
    fast_sqrt_table[i] = (s.i & 0x7FFFFF);
  }
}


inline float fastsqrt(float n)
{
  
  if (FP_BITS(n) == 0)
    return 0.0;                 // check for square root of 0
  
  FP_BITS(n) = fast_sqrt_table[(FP_BITS(n) >> 8) & 0xFFFF] | ((((FP_BITS(n) - 0x3F800000) >> 1) + 0x3F800000) & 0x7F800000);
  
  return n;
}


// At the assembly level the recommended workaround for the second FIST bug is the same for the first; 
// inserting the FRNDINT instruction immediately preceding the FIST instruction. 

__forceinline void FloatToInt(int *int_pointer, float f) 
{
	__asm  fld  f
  __asm  mov  edx,int_pointer
  __asm  FRNDINT
  __asm  fistp dword ptr [edx];

}



int main(int argc, char* argv[])
{

  float t, it, test_sqrt;
  int i = 0;

  build_sqrt_table();

  t = 1234.121234f;
  
  test_sqrt = fastsqrt(t);
  printf("sqrt expected %20.10f  approx %20.10f\n", sqrt(t), test_sqrt);

  FP_INV(it,t);
  printf("inv  expected %20.10f  approx %20.10f\n", 1/t, it);


  i = 0xdeafbabe;

  FloatToInt(&i, t);
  printf("ftol expected %d  actual %d %08X\n", (int)t, i, i);

  return 0;
}


/////////////////////////////////////////////////////////////////////
//  3D and geometry ops /////////////////////////////////////////////



//-----------------------------------------------------------------------------
// Name: CylTest_CapsFirst
// Orig: Greg James - gjames@NVIDIA.com
// Lisc: Free code - no warranty & no money back.  Use it all you want
// Desc: 
//    This function tests if the 3D point 'testpt' lies within an arbitrarily
// oriented cylinder.  The cylinder is defined by an axis from 'pt1' to 'pt2',
// the axis having a length squared of 'lengthsq' (pre-compute for each cylinder
// to avoid repeated work!), and radius squared of 'radius_sq'.
//    The function tests against the end caps first, which is cheap -> only 
// a single dot product to test against the parallel cylinder caps.  If the
// point is within these, more work is done to find the distance of the point
// from the cylinder axis.
//    Fancy Math (TM) makes the whole test possible with only two dot-products
// a subtract, and two multiplies.  For clarity, the 2nd mult is kept as a
// divide.  It might be faster to change this to a mult by also passing in
// 1/lengthsq and using that instead.
//    Elminiate the first 3 subtracts by specifying the cylinder as a base
// point on one end cap and a vector to the other end cap (pass in {dx,dy,dz}
// instead of 'pt2' ).
//
//    The dot product is constant along a plane perpendicular to a vector.
//    The magnitude of the cross product divided by one vector length is
// constant along a cylinder surface defined by the other vector as axis.
//
// Return:  -1.0 if point is outside the cylinder
// Return:  distance squared from cylinder axis if point is inside.
//
//-----------------------------------------------------------------------------

struct Vec3
{
	float x;
	float y;
	float z;
};

float CylTest_CapsFirst( const Vec3 & pt1, const Vec3 & pt2, float lengthsq, float radius_sq, const Vec3 & testpt )
{
	float dx, dy, dz;	// vector d  from line segment point 1 to point 2
	float pdx, pdy, pdz;	// vector pd from point 1 to test point
	float dot, dsq;

	dx = pt2.x - pt1.x;	// translate so pt1 is origin.  Make vector from
	dy = pt2.y - pt1.y;     // pt1 to pt2.  Need for this is easily eliminated
	dz = pt2.z - pt1.z;

	pdx = testpt.x - pt1.x;		// vector from pt1 to test point.
	pdy = testpt.y - pt1.y;
	pdz = testpt.z - pt1.z;

	// Dot the d and pd vectors to see if point lies behind the 
	// cylinder cap at pt1.x, pt1.y, pt1.z

	dot = pdx * dx + pdy * dy + pdz * dz;

	// If dot is less than zero the point is behind the pt1 cap.
	// If greater than the cylinder axis line segment length squared
	// then the point is outside the other end cap at pt2.

	if( dot < 0.0f || dot > lengthsq )
	{
		return( -1.0f );
	}
	else 
	{
		// Point lies within the parallel caps, so find
		// distance squared from point to line, using the fact that sin^2 + cos^2 = 1
		// the dot = cos() * |d||pd|, and cross*cross = sin^2 * |d|^2 * |pd|^2
		// Carefull: '*' means mult for scalars and dotproduct for vectors
		// In short, where dist is pt distance to cyl axis: 
		// dist = sin( pd to d ) * |pd|
		// distsq = dsq = (1 - cos^2( pd to d)) * |pd|^2
		// dsq = ( 1 - (pd * d)^2 / (|pd|^2 * |d|^2) ) * |pd|^2
		// dsq = pd * pd - dot * dot / lengthsq
		//  where lengthsq is d*d or |d|^2 that is passed into this function 

		// distance squared to the cylinder axis:

		dsq = (pdx*pdx + pdy*pdy + pdz*pdz) - dot*dot/lengthsq;

		if( dsq > radius_sq )
		{
			return( -1.0f );
		}
		else
		{
			return( dsq );		// return distance squared to axis
		}
	}
}


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
午夜私人影院久久久久| 亚洲免费在线播放| 色丁香久综合在线久综合在线观看| 国产一区二区久久| 极品少妇一区二区三区精品视频| 日韩成人午夜精品| 石原莉奈在线亚洲三区| 美腿丝袜亚洲一区| 毛片av一区二区| 国产成人亚洲精品青草天美| 成a人片国产精品| 日本乱码高清不卡字幕| 欧美日韩你懂得| 日韩天堂在线观看| 精品国产乱码久久| 国产日产欧美一区二区三区| 一区在线观看视频| 亚洲一区二区三区在线看| 日韩电影一二三区| 国产夫妻精品视频| 欧洲精品一区二区| 欧美电影免费观看高清完整版在线观看 | 丁香婷婷深情五月亚洲| av在线不卡免费看| 欧美精品v国产精品v日韩精品| 91精品国产欧美一区二区| 国产亚洲女人久久久久毛片| 中文字幕一区二区三区不卡在线| 亚洲午夜精品网| 国产在线视视频有精品| 91麻豆精东视频| 在线不卡免费欧美| 国产精品久久久久aaaa樱花| 婷婷综合另类小说色区| 成人综合婷婷国产精品久久蜜臀 | 久久精品在线观看| 一区2区3区在线看| 极品美女销魂一区二区三区| 成人永久免费视频| 日韩欧美一区二区久久婷婷| 国产精品全国免费观看高清 | 五月激情综合网| 成人小视频免费在线观看| 欧美视频你懂的| 国产视频一区二区三区在线观看 | 欧美成人a视频| 国产精品久线观看视频| 奇米精品一区二区三区四区 | 91丨porny丨最新| 欧美大度的电影原声| 亚洲精品国产精华液| 成人免费视频国产在线观看| 欧美电影免费观看高清完整版在| 亚洲黄色片在线观看| 国产成人av网站| 精品国产乱码久久久久久图片 | 三级成人在线视频| www.亚洲免费av| 久久久亚洲欧洲日产国码αv| 亚洲成av人片观看| 一本色道综合亚洲| 国产精品久久久久久久裸模 | 亚洲1区2区3区视频| 91日韩在线专区| 国产精品福利在线播放| 国产一区二区三区久久久| 欧美一区二区精品在线| 亚洲一二三专区| 欧美午夜精品久久久久久超碰| 亚洲色图在线播放| www.欧美精品一二区| 欧美激情一区二区在线| 国产乱码精品一区二区三| 欧美精品一区二区久久婷婷| 天堂在线一区二区| 欧美群妇大交群中文字幕| 亚洲高清视频在线| 欧美美女激情18p| 日韩av中文字幕一区二区三区| 欧美性色黄大片手机版| 亚洲综合色区另类av| 精品婷婷伊人一区三区三| 亚洲午夜精品在线| 欧美一区二区女人| 国产一区二区三区免费播放| 国产清纯在线一区二区www| 国产精品一区二区久久不卡| 国产精品卡一卡二卡三| 欧美午夜电影在线播放| 日本不卡123| 久久精品人人做人人爽97| 91免费国产在线观看| 亚洲电影第三页| 精品毛片乱码1区2区3区| 成人国产精品免费观看动漫| 亚洲美女偷拍久久| 日韩视频国产视频| 成人av网址在线观看| 亚洲一区在线观看免费| 精品国产一区二区在线观看| 懂色一区二区三区免费观看| 亚洲韩国一区二区三区| 欧美va在线播放| 91丨porny丨蝌蚪视频| 亚洲国产精品麻豆| xf在线a精品一区二区视频网站| 成人app软件下载大全免费| 午夜欧美电影在线观看| 欧美国产精品专区| 欧美日韩国产a| 暴力调教一区二区三区| 日本成人中文字幕在线视频| 国产精品色噜噜| 8v天堂国产在线一区二区| 成人小视频在线| 美脚の诱脚舐め脚责91| 一级精品视频在线观看宜春院| 日韩欧美国产系列| 欧美三级乱人伦电影| 国产成人久久精品77777最新版本| 亚洲欧美另类综合偷拍| 久久婷婷成人综合色| 7777女厕盗摄久久久| www.激情成人| 国产精品99久久不卡二区| 亚洲h精品动漫在线观看| 欧美激情艳妇裸体舞| 欧美电影免费观看高清完整版在线 | 亚洲精品v日韩精品| www久久久久| 精品嫩草影院久久| 91精品国产一区二区三区蜜臀 | 欧美性大战久久久| 99久久久精品| 国产福利91精品一区二区三区| 免费成人在线视频观看| 亚洲高清在线视频| 亚洲一区日韩精品中文字幕| 中文字幕一区二区三区精华液| 久久久噜噜噜久久中文字幕色伊伊 | 亚洲三级小视频| 中文字幕电影一区| 国产日韩精品久久久| 亚洲精品一区在线观看| 精品福利在线导航| 日韩欧美你懂的| 精品日韩在线观看| 欧美成人艳星乳罩| 日韩精品中文字幕一区 | 国产麻豆精品在线| 国产麻豆成人传媒免费观看| 精品一区二区三区不卡| 伦理电影国产精品| 国产一区二区伦理| 高清av一区二区| av高清久久久| 91麻豆免费看| 日本高清不卡在线观看| 一本一道波多野结衣一区二区| 欧美亚洲另类激情小说| 69堂成人精品免费视频| 日韩一区二区电影网| 精品盗摄一区二区三区| 久久精品水蜜桃av综合天堂| 国产欧美一区二区三区在线老狼| 久久久高清一区二区三区| 国产欧美日韩亚州综合| 综合激情网...| 亚洲妇熟xx妇色黄| 久久国产婷婷国产香蕉| 国产成人在线电影| 91久久线看在观草草青青| 9191成人精品久久| 久久久不卡网国产精品二区| 国产精品福利一区| 亚洲成av人片在www色猫咪| 精品一区精品二区高清| 成人免费视频一区| 欧美日韩国产首页| 久久午夜老司机| 亚洲综合一区二区| 国精品**一区二区三区在线蜜桃| 99视频精品在线| 日韩午夜电影av| 国产精品久久久久久久裸模 | 国产精品丝袜一区| 亚洲蜜桃精久久久久久久| 蜜桃av一区二区| 93久久精品日日躁夜夜躁欧美| 欧美日韩高清一区二区不卡| 久久久午夜精品| 婷婷丁香久久五月婷婷| 高清日韩电视剧大全免费| 欧美日韩情趣电影| 国产精品欧美久久久久无广告| 午夜精品一区二区三区免费视频| 国产黄人亚洲片| 日韩欧美一二三| 亚洲国产精品视频| 99这里只有精品|