x87 FPU ã§å³å¯ãªå精度æ¼ç®ãè¡ãã³ã¹ã
senna_hppã®æ¥è¨ããï¼
DirectXããå ¥ã£ãã®ã§ãæµ®åå°æ°ç¹æ¼ç®ã«ã¯floatåæ¼ç®ã使ãããã«ãªã£ãã®ã§ãããå®éã«ã¯doubleåã®æ¹ãéããããªã®ã§ãã®ç¢ºèªã®ããã®æ¤è¨¼å®é¨ã
(ä¸ç¥)
type add(ms) sub(ms) multi(ms) div(ms) double 203.6 201.9 5.6 5.4 flaot 913.4 912.9 674.0 675.1 double(template) 201.1 201.3 5.1 5.4 float (template) 913.8 915.0 680.2 675.5 double(template specialization) 201.7 201.5 6.5 4.7 float(template specialization) 913.6 912.2 674.0 674.2 çµæã¨ãã¦ã¯doubleåãå®å ¨åå©ã¨è¨ããã§ãããã
ãã ããPS2ãªã©ã¯floatåæ¼ç®ã®æ¹ãéãã®ã§ãå¦çç³»ãã³ã³ãã¤ã©ã«ãã£ã¦å¸¸ã«ãã®ãããªçµæã«ãªãã¨ã¯éãã¾ããã
試ãã«æå ã® Visual Studio 2005 ã§ãã³ã³ãã¤ã«ããã¦ã¿ã¾ãããï¼ãã£ã¹ã¢ã»ã³ãã«çµæãè¦ã¦ãã¨ï¼ä½ã¨ãªãç¶æ³ãèªãã¦ãããï¼Release ãã«ãã®ããã©ã«ãå¤ããæ³åããã«ï¼æããã³ã³ãã¤ã«ãªãã·ã§ã³ã®ãæµ®åå°æ°ç¹ã¢ãã«ãããPrecise (/fp:precise)ãã«ãªã£ã¦ããã®ãã¨æãã¾ãï¼
// double ç (éã) for(int i=0;i<N;++i) a1 += a2; 00401069 sub eax,1 0040106C fadd st(3),st 0040106E fadd st(2),st 00401070 fadd st(1),st 00401072 fadd st(3),st 00401074 fadd st(2),st 00401076 fadd st(1),st 00401078 fadd st(3),st 0040107A fadd st(2),st 0040107C fadd st(1),st 0040107E fadd st(3),st 00401080 fadd st(2),st 00401082 fadd st(1),st // float ç (é ã) for(int i=0;i<N;++i) a1 += a2; 004013AD fld dword ptr [esp+20h] 004013B1 fadd st,st(1) 004013B3 fstp dword ptr [esp+20h] 004013B7 fld dword ptr [esp+24h] 004013BB fadd st,st(1) 004013BD fstp dword ptr [esp+24h] 004013C1 fld dword ptr [esp+28h] 004013C5 fadd st,st(1) 004013C7 fstp dword ptr [esp+28h] 004013CB fld dword ptr [esp+20h] 004013CF fadd st,st(1) 004013D1 fstp dword ptr [esp+20h] 004013D5 fld dword ptr [esp+24h] 004013D9 fadd st,st(1) 004013DB fstp dword ptr [esp+24h] 004013DF fld dword ptr [esp+28h]
詳細ã«ã¤ãã¦ã¯ä»¥åã®æ¥è¨ãä¾ã®è¨äºã§æ¸ããã®ã§çç¥ãã¾ããï¼åé¡ã® float çã§ã¯ï¼é£ç¶ã㦠fadd ãã¦ããã¨ææ°é¨ã 80-bit 精度ã§è¨ç®ããç¶ãã¦ãã¾ãããï¼æ¯åã¡ã¢ãªã«æ¸ãåºãã¦èªã¿ç´ããã¨ã§å精度ã§ã®å®å
¨ä¸¸ããè¡ã£ã¦ããããã§ã*1ï¼
è¦ãããã«æ²æ¨ã§ããï¼ãããã£ã¦ããã©ã¼ãã³ã¹å·®ã¨ä¸ç·ã«è¦ããããã¨ç¢ºãã«ã¤ã³ãã¯ãããã¾ãããï¼
ã¡ãªã¿ã«ãã®ãã¹ãã³ã¼ãã§ãæµ®åå°æ°ç¹ã¢ãã«ãããFast (/fp:fast)ãã«ããã¨ï¼æ¦ã float ã®æ¹ãéãã¨ããçµæã«ãªãããã§ã*2ï¼
CodeZine ã®è¨äºç¨ã«ä½ã£ããã©çµå±ä½¿ããªãã£ãå³ãã¤ãã§ã«è²¼ã£ã¦ã¿ããï¼
*1:store-reload 㧠FP-strict ãªå精度æ¼ç®ãå®ç¾ã§ãããã¨ã«ã¤ãã¦ã¯ï¼é¦è¤æ°ã®ãå³å¯ãªæµ®åå°æ°ç¹æ¼ç®ã»ãã³ãã£ã¯ã¹ã® Java å®è¡æã³ã³ãã¤ã©ã¸ã®å®è£ ãåç §ã®ãã¨
*2:追è¨ï¼ã¨ã¯ããã»ã¨ãã©å·®ã¯ãªã