flat assembler
Message board for the users of flat assembler.

Index > Main > double pow(double base, double exponent)

Author
Thread Post new topic Reply to topic
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Hello
I am writing graphics engine for my OS.
As i need certain std stuff along the way.
Writing an integer pow is easy but for doubles?

C Prototype from math library is like...
Quote:

double pow(double base, double exponent)


I am creating gammatized palette on the fly.
So far its still in C but it is used like so...
Code:
unsigned char GetGammaLevel(double factor, int sellevels, int pallevels, int index)
{
   double intensity;
   double power;
   unsigned char result;

   result = 0;
   sellevels--;
   pallevels--;

   if(index > 0)
   {
      intensity = (double)index / (double)sellevels;
      power = pow(intensity, 1.0 / factor);
      result = (unsigned char)((power * pallevels) + 0.5);
   }

   return result;
}

void InitPalette(unsigned char palette[768])
{
   int red;
   int green;
   int blue;
   int index;
   int index2;
   unsigned char level;

   for(red = 0; red < 4; red++)
   {
      for(green = 0; green < 4; green++)
      {
         for(blue = 0; blue < 4; blue++)
         {
            index = ((red << 4) + (green << 2) + blue) * 3;

            palette[index]   = GetGammaLevel(2.3,4,64,red);
            palette[index+1] = GetGammaLevel(2.3,4,64,green);
            palette[index+2] = GetGammaLevel(2.3,4,64,blue);
         }
      }
   }

   for(index = 0; index < 64; index++)
   {
      level = GetGammaLevel(2.3,64,64,index);

      index2 = (index + 64) * 3;
      palette[index2] = level;
      palette[index2+1] = 0;
      palette[index2+2] = 0;

      index2 = (index + 128) * 3;
      palette[index2] = 0;
      palette[index2+1] = level;
      palette[index2+2] = 0;

      index2 = (index + 192) * 3;
      palette[index2] = 0;
      palette[index2+1] = 0;
      palette[index2+2] = level;
   }
}    

I have all this C code from my engine i have to port.
If you feel like helping out i would be very happy.

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 25 Jul 2009, 03:48
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:48; edited 1 time in total
Post 25 Jul 2009, 13:55
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
I wish it were that simple.
After searching the net for days i have found 1 example in masm.
Now if i can just figure out how it really works Confused
I just got olly so im gonna go see how MS-VC6 does it.
These things always turn out way more complex than i forsee.
Post 25 Jul 2009, 14:38
View user's profile Send private message Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael
pow(x, y) = exp(ln(x) * y)
Post 25 Jul 2009, 14:44
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:48; edited 1 time in total
Post 25 Jul 2009, 14:51
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
asmcoder this is about floating point, not integers. It can be much FASTER because you already have the exponent stored along with the mantissa, so the base 2 logarithm is extremely fast (there's even an instruction for that IIRC) you just take the exponent.

See Fanael's formula.

see this for instance:

http://www.website.masmforum.com/tutorials/fptute/fpuchap11.htm
Post 25 Jul 2009, 14:55
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

did you had in school long multiplication?

Did you had in school non natural exponents? You know, things like 3^(-2.5), for instance.
Post 25 Jul 2009, 18:02
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:48; edited 1 time in total
Post 25 Jul 2009, 18:28
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Hello bitshifter,
If you need a pow() function you can use the one in the msvcrt.dll which, I believe, is included with every windows OS version since 2000. I've posted the api defines below. You'll have to use 'cinvoke' macro to call it in fasm, and use the 'double' keyword to push double-floats onto the stack. Some Examples:

Code:
locals dfloat:QWORD, dvara:QWORD, dvarb:QWORD

cinvoke pow, double 5.0, double 2.0
fstp     [dfloat]

cinvoke pow, double [dvara], double [dvarb]
fstp     [dfloat]    


Code:
import msvcrt,\
       _CIacos,'_CIacos',\
       _CIasin,'_CIasin',\
       _CIatan,'_CIatan',\
       _CIatan2,'_CIatan2',\
       _CIcos,'_CIcos',\
       _CIcosh,'_CIcosh',\
       _CIexp,'_CIexp',\
       _CIfmod,'_CIfmod',\
       _CIlog,'_CIlog',\
       _CIlog10,'_CIlog10',\
       _CIpow,'_CIpow',\
       _CIsin,'_CIsin',\
       _CIsinh,'_CIsinh',\
       _CIsqrt,'_CIsqrt',\
       _CItan,'_CItan',\
       _CItanh,'_CItanh',\
       _CxxThrowException,'_CxxThrowException',\
       _EH_prolog,'_EH_prolog',\
       _Getdays,'_Getdays',\
       _Getmonths,'_Getmonths',\
       _Gettnames,'_Gettnames',\
       _HUGE,'_HUGE',\
       _Strftime,'_Strftime',\
       _XcptFilter,'_XcptFilter',\
       __CxxCallUnwindDtor,'__CxxCallUnwindDtor',\
       __CxxDetectRethrow,'__CxxDetectRethrow',\
       __CxxExceptionFilter,'__CxxExceptionFilter',\
       __CxxFrameHandler,'__CxxFrameHandler',\
       __CxxLongjmpUnwind,'__CxxLongjmpUnwind',\
       __CxxQueryExceptionSize,'__CxxQueryExceptionSize',\
       __CxxRegisterExceptionObject,'__CxxRegisterExceptionObject',\
       __CxxUnregisterExceptionObject,'__CxxUnregisterExceptionObject',\
       __DestructExceptionObject,'__DestructExceptionObject',\
       __RTCastToVoid,'__RTCastToVoid',\
       __RTDynamicCast,'__RTDynamicCast',\
       __RTtypeid,'__RTtypeid',\
       __STRINGTOLD,'__STRINGTOLD',\
       ___lc_codepage_func,'___lc_codepage_func',\
       ___lc_handle_func,'___lc_handle_func',\
       ___mb_cur_max_func,'___mb_cur_max_func',\
       ___setlc_active_func,'___setlc_active_func',\
       ___unguarded_readlc_active_add_func,'___unguarded_readlc_active_add_func',\
       __argc,'__argc',\
       __argv,'__argv',\
       __badioinfo,'__badioinfo',\
       __crtCompareString ,'__crtCompareStringA',\
       __crtLCMapString ,'__crtLCMapStringA',\
       __dllonexit,'__dllonexit',\
       __doserrno,'__doserrno',\
       __fpecode,'__fpecode',\
       __getmainargs,'__getmainargs',\
       __initenv,'__initenv',\
       __iob_func,'__iob_func',\
       __isascii,'__isascii',\
       __iscsym,'__iscsym',\
       __iscsymf,'__iscsymf',\
       __lc_codepage,'__lc_codepage',\
       __lc_collate_cp,'__lc_collate_cp',\
       __lc_handle,'__lc_handle',\
       __lconv_init,'__lconv_init',\
       __mb_cur_max,'__mb_cur_max',\
       __p___argc,'__p___argc',\
       __p___argv,'__p___argv',\
       __p___initenv,'__p___initenv',\
       __p___mb_cur_max,'__p___mb_cur_max',\
       __p___wargv,'__p___wargv',\
       __p___winitenv,'__p___winitenv',\
       __p__acmdln,'__p__acmdln',\
       __p__amblksiz,'__p__amblksiz',\
       __p__commode,'__p__commode',\
       __p__daylight,'__p__daylight',\
       __p__dstbias,'__p__dstbias',\
       __p__environ,'__p__environ',\
       __p__fileinfo,'__p__fileinfo',\
       __p__fmode,'__p__fmode',\
       __p__iob,'__p__iob',\
       __p__mbcasemap,'__p__mbcasemap',\
       __p__mbctype,'__p__mbctype',\
       __p__osver,'__p__osver',\
       __p__pctype,'__p__pctype',\
       __p__pgmptr,'__p__pgmptr',\
       __p__pwctype,'__p__pwctype',\
       __p__timezone,'__p__timezone',\
       __p__tzname,'__p__tzname',\
       __p__wcmdln,'__p__wcmdln',\
       __p__wenviron,'__p__wenviron',\
       __p__winmajor,'__p__winmajor',\
       __p__winminor,'__p__winminor',\
       __p__winver,'__p__winver',\
       __p__wpgmptr,'__p__wpgmptr',\
       __pctype_func,'__pctype_func',\
       __pioinfo,'__pioinfo',\
       __pxcptinfoptrs,'__pxcptinfoptrs',\
       __set_app_type,'__set_app_type',\
       __setlc_active,'__setlc_active',\
       __setusermatherr,'__setusermatherr',\
       __threadhandle,'__threadhandle',\
       __threadid,'__threadid',\
       __toascii,'__toascii',\
       __unDName,'__unDName',\
       __unDNameEx,'__unDNameEx',\
       __uncaught_exception,'__uncaught_exception',\
       __unguarded_readlc_active,'__unguarded_readlc_active',\
       __wargv,'__wargv',\
       __wcserror,'__wcserror',\
       __wgetmainargs,'__wgetmainargs',\
       __winitenv,'__winitenv',\
       _abnormal_termination,'_abnormal_termination',\
       _access,'_access',\
       _acmdln,'_acmdln',\
       _adj_fdiv_m16i,'_adj_fdiv_m16i',\
       _adj_fdiv_m32,'_adj_fdiv_m32',\
       _adj_fdiv_m32i,'_adj_fdiv_m32i',\
       _adj_fdiv_m64,'_adj_fdiv_m64',\
       _adj_fdiv_r,'_adj_fdiv_r',\
       _adj_fdivr_m16i,'_adj_fdivr_m16i',\
       _adj_fdivr_m32,'_adj_fdivr_m32',\
       _adj_fdivr_m32i,'_adj_fdivr_m32i',\
       _adj_fdivr_m64,'_adj_fdivr_m64',\
       _adj_fpatan,'_adj_fpatan',\
       _adj_fprem,'_adj_fprem',\
       _adj_fprem1,'_adj_fprem1',\
       _adj_fptan,'_adj_fptan',\
       _adjust_fdiv,'_adjust_fdiv',\
       _aexit_rtn,'_aexit_rtn',\
       _aligned_free,'_aligned_free',\
       _aligned_malloc,'_aligned_malloc',\
       _aligned_offset_malloc,'_aligned_offset_malloc',\
       _aligned_offset_realloc,'_aligned_offset_realloc',\
       _aligned_realloc,'_aligned_realloc',\
       _amsg_exit,'_amsg_exit',\
       _assert,'_assert',\
       _atodbl,'_atodbl',\
       _atoi64,'_atoi64',\
       _atoldbl,'_atoldbl',\
       _beep,'_beep',\
       _beginthread,'_beginthread',\
       _beginthreadex,'_beginthreadex',\
       _c_exit,'_c_exit',\
       _cabs,'_cabs',\
       _callnewh,'_callnewh',\
       _cexit,'_cexit',\
       _cgets,'_cgets',\
       _cgetws,'_cgetws',\
       _chdir,'_chdir',\
       _chdrive,'_chdrive',\
       _chgsign,'_chgsign',\
       _chkesp,'_chkesp',\
       _chmod,'_chmod',\
       _chsize,'_chsize',\
       _clearfp,'_clearfp',\
       _close,'_close',\
       _commit,'_commit',\
       _commode,'_commode',\
       _control87,'_control87',\
       _controlfp,'_controlfp',\
       _copysign,'_copysign',\
       _cprintf,'_cprintf',\
       _cputs,'_cputs',\
       _cputws,'_cputws',\
       _creat,'_creat',\
       _cscanf,'_cscanf',\
       _ctime64,'_ctime64',\
       _ctype,'_ctype',\
       _cwait,'_cwait',\
       _cwprintf,'_cwprintf',\
       _cwscanf,'_cwscanf',\
       _daylight,'_daylight',\
       _dstbias,'_dstbias',\
       _dup,'_dup',\
       _dup2,'_dup2',\
       _ecvt,'_ecvt',\
       _endthread,'_endthread',\
       _endthreadex,'_endthreadex',\
       _environ,'_environ',\
       _eof,'_eof',\
       _errno,'_errno',\
       _except_handler2,'_except_handler2',\
       _except_handler3,'_except_handler3',\
       _execl,'_execl',\
       _execle,'_execle',\
       _execlp,'_execlp',\
       _execlpe,'_execlpe',\
       _execv,'_execv',\
       _execve,'_execve',\
       _execvp,'_execvp',\
       _execvpe,'_execvpe',\
       _exit,'_exit',\
       _expand,'_expand',\
       _fcloseall,'_fcloseall',\
       _fcvt,'_fcvt',\
       _fdopen,'_fdopen',\
       _fgetchar,'_fgetchar',\
       _fgetwchar,'_fgetwchar',\
       _filbuf,'_filbuf',\
       _fileinfo,'_fileinfo',\
       _filelength,'_filelength',\
       _filelengthi64,'_filelengthi64',\
       _fileno,'_fileno',\
       _findclose,'_findclose',\
       _findfirst,'_findfirst',\
       _findfirst64,'_findfirst64',\
       _findfirsti64,'_findfirsti64',\
       _findnext,'_findnext',\
       _findnext64,'_findnext64',\
       _findnexti64,'_findnexti64',\
       _finite,'_finite',\
       _flsbuf,'_flsbuf',\
       _flushall,'_flushall',\
       _fmode,'_fmode',\
       _fpclass,'_fpclass',\
       _fpieee_flt,'_fpieee_flt',\
       _fpreset,'_fpreset',\
       _fputchar,'_fputchar',\
       _fputwchar,'_fputwchar',\
       _fsopen,'_fsopen',\
       _fstat,'_fstat',\
       _fstat64,'_fstat64',\
       _fstati64,'_fstati64',\
       _ftime,'_ftime',\
       _ftime64,'_ftime64',\
       _ftol,'_ftol',\
       _fullpath,'_fullpath',\
       _futime,'_futime',\
       _futime64,'_futime64',\
       _gcvt,'_gcvt',\
       _get_heap_handle,'_get_heap_handle',\
       _get_osfhandle,'_get_osfhandle',\
       _get_sbh_threshold,'_get_sbh_threshold',\
       _getch,'_getch',\
       _getche,'_getche',\
       _getcwd,'_getcwd',\
       _getdcwd,'_getdcwd',\
       _getdiskfree,'_getdiskfree',\
       _getdllprocaddr,'_getdllprocaddr',\
       _getdrive,'_getdrive',\
       _getdrives,'_getdrives',\
       _getmaxstdio,'_getmaxstdio',\
       _getmbcp,'_getmbcp',\
       _getpid,'_getpid',\
       _getsystime,'_getsystime',\
       _getw,'_getw',\
       _getwch,'_getwch',\
       _getwche,'_getwche',\
       _getws,'_getws',\
       _global_unwind2,'_global_unwind2',\
       _gmtime64,'_gmtime64',\
       _heapadd,'_heapadd',\
       _heapchk,'_heapchk',\
       _heapmin,'_heapmin',\
       _heapset,'_heapset',\
       _heapused,'_heapused',\
       _heapwalk,'_heapwalk',\
       _hypot,'_hypot',\
       _i64toa,'_i64toa',\
       _i64tow,'_i64tow',\
       _initterm,'_initterm',\
       _inp,'_inp',\
       _inpd,'_inpd',\
       _inpw,'_inpw',\
       _iob,'_iob',\
       _isatty,'_isatty',\
       _isctype,'_isctype',\
       _ismbbalnum,'_ismbbalnum',\
       _ismbbalpha,'_ismbbalpha',\
       _ismbbgraph,'_ismbbgraph',\
       _ismbbkalnum,'_ismbbkalnum',\
       _ismbbkana,'_ismbbkana',\
       _ismbbkprint,'_ismbbkprint',\
       _ismbbkpunct,'_ismbbkpunct',\
       _ismbblead,'_ismbblead',\
       _ismbbprint,'_ismbbprint',\
       _ismbbpunct,'_ismbbpunct',\
       _ismbbtrail,'_ismbbtrail',\
       _ismbcalnum,'_ismbcalnum',\
       _ismbcalpha,'_ismbcalpha',\
       _ismbcdigit,'_ismbcdigit',\
       _ismbcgraph,'_ismbcgraph',\
       _ismbchira,'_ismbchira',\
       _ismbckata,'_ismbckata',\
       _ismbcl0,'_ismbcl0',\
       _ismbcl1,'_ismbcl1',\
       _ismbcl2,'_ismbcl2',\
       _ismbclegal,'_ismbclegal',\
       _ismbclower,'_ismbclower',\
       _ismbcprint,'_ismbcprint',\
       _ismbcpunct,'_ismbcpunct',\
       _ismbcspace,'_ismbcspace',\
       _ismbcsymbol,'_ismbcsymbol',\
       _ismbcupper,'_ismbcupper',\
       _ismbslead,'_ismbslead',\
       _ismbstrail,'_ismbstrail',\
       _isnan,'_isnan',\
       _itoa,'_itoa',\
       _itow,'_itow',\
       _j0,'_j0',\
       _j1,'_j1',\
       _jn,'_jn',\
       _kbhit,'_kbhit',\
       _lfind,'_lfind',\
       _loaddll,'_loaddll',\
       _local_unwind2,'_local_unwind2',\
       _localtime64,'_localtime64',\
       _lock,'_lock',\
       _locking,'_locking',\
       _logb,'_logb',\
       _longjmpex,'_longjmpex',\
       _lrotl,'_lrotl',\
       _lrotr,'_lrotr',\
       _lsearch,'_lsearch',\
       _lseek,'_lseek',\
       _lseeki64,'_lseeki64',\
       _ltoa,'_ltoa',\
       _ltow,'_ltow',\
       _makepath,'_makepath',\
       _mbbtombc,'_mbbtombc',\
       _mbbtype,'_mbbtype',\
       _mbcasemap,'_mbcasemap',\
       _mbccpy,'_mbccpy',\
       _mbcjistojms,'_mbcjistojms',\
       _mbcjmstojis,'_mbcjmstojis',\
       _mbclen,'_mbclen',\
       _mbctohira,'_mbctohira',\
       _mbctokata,'_mbctokata',\
       _mbctolower,'_mbctolower',\
       _mbctombb,'_mbctombb',\
       _mbctoupper,'_mbctoupper',\
       _mbctype,'_mbctype',\
       _mbsbtype,'_mbsbtype',\
       _mbscat,'_mbscat',\
       _mbschr,'_mbschr',\
       _mbscmp,'_mbscmp',\
       _mbscoll,'_mbscoll',\
       _mbscpy,'_mbscpy',\
       _mbscspn,'_mbscspn',\
       _mbsdec,'_mbsdec',\
       _mbsdup,'_mbsdup',\
       _mbsicmp,'_mbsicmp',\
       _mbsicoll,'_mbsicoll',\
       _mbsinc,'_mbsinc',\
       _mbslen,'_mbslen',\
       _mbslwr,'_mbslwr',\
       _mbsnbcat,'_mbsnbcat',\
       _mbsnbcmp,'_mbsnbcmp',\
       _mbsnbcnt,'_mbsnbcnt',\
       _mbsnbcoll,'_mbsnbcoll',\
       _mbsnbcpy,'_mbsnbcpy',\
       _mbsnbicmp,'_mbsnbicmp',\
       _mbsnbicoll,'_mbsnbicoll',\
       _mbsnbset,'_mbsnbset',\
       _mbsncat,'_mbsncat',\
       _mbsnccnt,'_mbsnccnt',\
       _mbsncmp,'_mbsncmp',\
       _mbsncoll,'_mbsncoll',\
       _mbsncpy,'_mbsncpy',\
       _mbsnextc,'_mbsnextc',\
       _mbsnicmp,'_mbsnicmp',\
       _mbsnicoll,'_mbsnicoll',\
       _mbsninc,'_mbsninc',\
       _mbsnset,'_mbsnset',\
       _mbspbrk,'_mbspbrk',\
       _mbsrchr,'_mbsrchr',\
       _mbsrev,'_mbsrev',\
       _mbsset,'_mbsset',\
       _mbsspn,'_mbsspn',\
       _mbsspnp,'_mbsspnp',\
       _mbsstr,'_mbsstr',\
       _mbstok,'_mbstok',\
       _mbstrlen,'_mbstrlen',\
       _mbsupr,'_mbsupr',\
       _memccpy,'_memccpy',\
       _memicmp,'_memicmp',\
       _mkdir,'_mkdir',\
       _mktemp,'_mktemp',\
       _mktime64,'_mktime64',\
       _msize,'_msize',\
       _nextafter,'_nextafter',\
       _onexit,'_onexit',\
       _open,'_open',\
       _open_osfhandle,'_open_osfhandle',\
       _osplatform,'_osplatform',\
       _osver,'_osver',\
       _outp,'_outp',\
       _outpd,'_outpd',\
       _outpw,'_outpw',\
       _pclose,'_pclose',\
       _pctype,'_pctype',\
       _pgmptr,'_pgmptr',\
       _pipe,'_pipe',\
       _popen,'_popen',\
       _purecall,'_purecall',\
       _putch,'_putch',\
       _putenv,'_putenv',\
       _putw,'_putw',\
       _putwch,'_putwch',\
       _putws,'_putws',\
       _pwctype,'_pwctype',\
       _read,'_read',\
       _resetstkoflw,'_resetstkoflw',\
       _rmdir,'_rmdir',\
       _rmtmp,'_rmtmp',\
       _rotl,'_rotl',\
       _rotr,'_rotr',\
       _safe_fdiv,'_safe_fdiv',\
       _safe_fdivr,'_safe_fdivr',\
       _safe_fprem,'_safe_fprem',\
       _safe_fprem1,'_safe_fprem1',\
       _scalb,'_scalb',\
       _scprintf,'_scprintf',\
       _scwprintf,'_scwprintf',\
       _searchenv,'_searchenv',\
       _seh_longjmp_unwind,'_seh_longjmp_unwind',\
       _set_SSE2_enable,'_set_SSE2_enable',\
       _set_error_mode,'_set_error_mode',\
       _set_sbh_threshold,'_set_sbh_threshold',\
       _seterrormode,'_seterrormode',\
       _setjmp,'_setjmp',\
       _setjmp3,'_setjmp3',\
       _setmaxstdio,'_setmaxstdio',\
       _setmbcp,'_setmbcp',\
       _setmode,'_setmode',\
       _setsystime,'_setsystime',\
       _sleep,'_sleep',\
       _snprintf,'_snprintf',\
       _snscanf,'_snscanf',\
       _snwprintf,'_snwprintf',\
       _snwscanf,'_snwscanf',\
       _sopen,'_sopen',\
       _spawnl,'_spawnl',\
       _spawnle,'_spawnle',\
       _spawnlp,'_spawnlp',\
       _spawnlpe,'_spawnlpe',\
       _spawnv,'_spawnv',\
       _spawnve,'_spawnve',\
       _spawnvp,'_spawnvp',\
       _spawnvpe,'_spawnvpe',\
       _splitpath,'_splitpath',\
       _stat,'_stat',\
       _stat64,'_stat64',\
       _stati64,'_stati64',\
       _statusfp,'_statusfp',\
       _strcmpi,'_strcmpi',\
       _strdate,'_strdate',\
       _strdup,'_strdup',\
       _strerror,'_strerror',\
       _stricmp,'_stricmp',\
       _stricoll,'_stricoll',\
       _strlwr,'_strlwr',\
       _strncoll,'_strncoll',\
       _strnicmp,'_strnicmp',\
       _strnicoll,'_strnicoll',\
       _strnset,'_strnset',\
       _strrev,'_strrev',\
       _strset,'_strset',\
       _strtime,'_strtime',\
       _strtoi64,'_strtoi64',\
       _strtoui64,'_strtoui64',\
       _strupr,'_strupr',\
       _swab,'_swab',\
       _sys_errlist,'_sys_errlist',\
       _sys_nerr,'_sys_nerr',\
       _tell,'_tell',\
       _telli64,'_telli64',\
       _tempnam,'_tempnam',\
       _time64,'_time64',\
       _timezone,'_timezone',\
       _tolower,'_tolower',\
       _toupper,'_toupper',\
       _tzname,'_tzname',\
       _tzset,'_tzset',\
       _ui64toa,'_ui64toa',\
       _ui64tow,'_ui64tow',\
       _ultoa,'_ultoa',\
       _ultow,'_ultow',\
       _umask,'_umask',\
       _ungetch,'_ungetch',\
       _ungetwch,'_ungetwch',\
       _unlink,'_unlink',\
       _unloaddll,'_unloaddll',\
       _unlock,'_unlock',\
       _utime,'_utime',\
       _utime64,'_utime64',\
       _vscprintf,'_vscprintf',\
       _vscwprintf,'_vscwprintf',\
       _vsnprintf,'_vsnprintf',\
       _vsnwprintf,'_vsnwprintf',\
       _waccess,'_waccess',\
       _wasctime,'_wasctime',\
       _wchdir,'_wchdir',\
       _wchmod,'_wchmod',\
       _wcmdln,'_wcmdln',\
       _wcreat,'_wcreat',\
       _wcsdup,'_wcsdup',\
       _wcserror,'_wcserror',\
       _wcsicmp,'_wcsicmp',\
       _wcsicoll,'_wcsicoll',\
       _wcslwr,'_wcslwr',\
       _wcsncoll,'_wcsncoll',\
       _wcsnicmp,'_wcsnicmp',\
       _wcsnicoll,'_wcsnicoll',\
       _wcsnset,'_wcsnset',\
       _wcsrev,'_wcsrev',\
       _wcsset,'_wcsset',\
       _wcstoi64,'_wcstoi64',\
       _wcstoui64,'_wcstoui64',\
       _wcsupr,'_wcsupr',\
       _wctime,'_wctime',\
       _wctime64,'_wctime64',\
       _wenviron,'_wenviron',\
       _wexecl,'_wexecl',\
       _wexecle,'_wexecle',\
       _wexeclp,'_wexeclp',\
       _wexeclpe,'_wexeclpe',\
       _wexecv,'_wexecv',\
       _wexecve,'_wexecve',\
       _wexecvp,'_wexecvp',\
       _wexecvpe,'_wexecvpe',\
       _wfdopen,'_wfdopen',\
       _wfindfirst,'_wfindfirst',\
       _wfindfirst64,'_wfindfirst64',\
       _wfindfirsti64,'_wfindfirsti64',\
       _wfindnext,'_wfindnext',\
       _wfindnext64,'_wfindnext64',\
       _wfindnexti64,'_wfindnexti64',\
       _wfopen,'_wfopen',\
       _wfreopen,'_wfreopen',\
       _wfsopen,'_wfsopen',\
       _wfullpath,'_wfullpath',\
       _wgetcwd,'_wgetcwd',\
       _wgetdcwd,'_wgetdcwd',\
       _wgetenv,'_wgetenv',\
       _winmajor,'_winmajor',\
       _winminor,'_winminor',\
       _winver,'_winver',\
       _wmakepath,'_wmakepath',\
       _wmkdir,'_wmkdir',\
       _wmktemp,'_wmktemp',\
       _wopen,'_wopen',\
       _wperror,'_wperror',\
       _wpgmptr,'_wpgmptr',\
       _wpopen,'_wpopen',\
       _wputenv,'_wputenv',\
       _wremove,'_wremove',\
       _wrename,'_wrename',\
       _write,'_write',\
       _wrmdir,'_wrmdir',\
       _wsearchenv,'_wsearchenv',\
       _wsetlocale,'_wsetlocale',\
       _wsopen,'_wsopen',\
       _wspawnl,'_wspawnl',\
       _wspawnle,'_wspawnle',\
       _wspawnlp,'_wspawnlp',\
       _wspawnlpe,'_wspawnlpe',\
       _wspawnv,'_wspawnv',\
       _wspawnve,'_wspawnve',\
       _wspawnvp,'_wspawnvp',\
       _wspawnvpe,'_wspawnvpe',\
       _wsplitpath,'_wsplitpath',\
       _wstat,'_wstat',\
       _wstat64,'_wstat64',\
       _wstati64,'_wstati64',\
       _wstrdate,'_wstrdate',\
       _wstrtime,'_wstrtime',\
       _wsystem,'_wsystem',\
       _wtempnam,'_wtempnam',\
       _wtmpnam,'_wtmpnam',\
       _wtof,'_wtof',\
       _wtoi,'_wtoi',\
       _wtoi64,'_wtoi64',\
       _wtol,'_wtol',\
       _wunlink,'_wunlink',\
       _wutime,'_wutime',\
       _wutime64,'_wutime64',\
       _y0,'_y0',\
       _y1,'_y1',\
       _yn,'_yn',\
       abort,'abort',\
       abs,'abs',\
       acos,'acos',\
       asctime,'asctime',\
       asin,'asin',\
       atan,'atan',\
       atan2,'atan2',\
       atexit,'atexit',\
       atof,'atof',\
       atoi,'atoi',\
       atol,'atol',\
       bsearch,'bsearch',\
       calloc,'calloc',\
       ceil,'ceil',\
       clearerr,'clearerr',\
       clock,'clock',\
       cos,'cos',\
       cosh,'cosh',\
       ctime,'ctime',\
       difftime,'difftime',\
       cdiv,'div',\
       exit,'exit',\
       exp,'exp',\
       cfabs,'fabs',\
       fclose,'fclose',\
       feof,'feof',\
       ferror,'ferror',\
       fflush,'fflush',\
       fgetc,'fgetc',\
       fgetpos,'fgetpos',\
       fgets,'fgets',\
       fgetwc,'fgetwc',\
       fgetws,'fgetws',\
       floor,'floor',\
       fmod,'fmod',\
       fopen,'fopen',\
       fprintf,'fprintf',\
       fputc,'fputc',\
       fputs,'fputs',\
       fputwc,'fputwc',\
       fputws,'fputws',\
       fread,'fread',\
       free,'free',\
       freopen,'freopen',\
       frexp,'frexp',\
       fscanf,'fscanf',\
       fseek,'fseek',\
       fsetpos,'fsetpos',\
       ftell,'ftell',\
       fwprintf,'fwprintf',\
       fwrite,'fwrite',\
       fwscanf,'fwscanf',\
       getc,'getc',\
       getchar,'getchar',\
       getenv,'getenv',\
       gets,'gets',\
       getwc,'getwc',\
       getwchar,'getwchar',\
       gmtime,'gmtime',\
       is_wctype,'is_wctype',\
       isalnum,'isalnum',\
       isalpha,'isalpha',\
       iscntrl,'iscntrl',\
       isdigit,'isdigit',\
       isgraph,'isgraph',\
       isleadbyte,'isleadbyte',\
       islower,'islower',\
       isprint,'isprint',\
       ispunct,'ispunct',\
       isspace,'isspace',\
       isupper,'isupper',\
       iswalnum,'iswalnum',\
       iswalpha,'iswalpha',\
       iswascii,'iswascii',\
       iswcntrl,'iswcntrl',\
       iswctype,'iswctype',\
       iswdigit,'iswdigit',\
       iswgraph,'iswgraph',\
       iswlower,'iswlower',\
       iswprint,'iswprint',\
       iswpunct,'iswpunct',\
       iswspace,'iswspace',\
       iswupper,'iswupper',\
       iswxdigit,'iswxdigit',\
       isxdigit,'isxdigit',\
       labs,'labs',\
       ldexp,'ldexp',\
       ldiv,'ldiv',\
       localeconv,'localeconv',\
       localtime,'localtime',\
       log,'log',\
       log10,'log10',\
       longjmp,'longjmp',\
       malloc,'malloc',\
       mblen,'mblen',\
       mbstowcs,'mbstowcs',\
       mbtowc,'mbtowc',\
       memchr,'memchr',\
       memcmp,'memcmp',\
       memcpy,'memcpy',\
       memmove,'memmove',\
       memset,'memset',\
       mktime,'mktime',\
       modf,'modf',\
       perror,'perror',\
       pow,'pow',\
       printf,'printf',\
       putc,'putc',\
       putchar,'putchar',\
       puts,'puts',\
       putwc,'putwc',\
       putwchar,'putwchar',\
       qsort,'qsort',\
       raise,'raise',\
       rand,'rand',\
       realloc,'realloc',\
       remove,'remove',\
       rename,'rename',\
       rewind,'rewind',\
       scanf,'scanf',\
       setbuf,'setbuf',\
       setlocale,'setlocale',\
       setvbuf,'setvbuf',\
       signal,'signal',\
       sin,'sin',\
       sinh,'sinh',\
       sprintf,'sprintf',\
       sqrt,'sqrt',\
       srand,'srand',\
       sscanf,'sscanf',\
       strcat,'strcat',\
       strchr,'strchr',\
       strcmp,'strcmp',\
       strcoll,'strcoll',\
       strcpy,'strcpy',\
       strcspn,'strcspn',\
       strerror,'strerror',\
       strftime,'strftime',\
       strlen,'strlen',\
       strncat,'strncat',\
       strncmp,'strncmp',\
       strncpy,'strncpy',\
       strpbrk,'strpbrk',\
       strrchr,'strrchr',\
       strspn,'strspn',\
       strstr,'strstr',\
       strtod,'strtod',\
       strtok,'strtok',\
       strtol,'strtol',\
       strtoul,'strtoul',\
       strxfrm,'strxfrm',\
       swprintf,'swprintf',\
       swscanf,'swscanf',\
       system,'system',\
       tan,'tan',\
       tanh,'tanh',\
       time,'time',\
       tmpfile,'tmpfile',\
       tmpnam,'tmpnam',\
       tolower,'tolower',\
       toupper,'toupper',\
       towlower,'towlower',\
       towupper,'towupper',\
       ungetc,'ungetc',\
       ungetwc,'ungetwc',\
       vfprintf,'vfprintf',\
       vfwprintf,'vfwprintf',\
       vprintf,'vprintf',\
       vsprintf,'vsprintf',\
       vswprintf,'vswprintf',\
       vwprintf,'vwprintf',\
       wcscat,'wcscat',\
       wcschr,'wcschr',\
       wcscmp,'wcscmp',\
       wcscoll,'wcscoll',\
       wcscpy,'wcscpy',\
       wcscspn,'wcscspn',\
       wcsftime,'wcsftime',\
       wcslen,'wcslen',\
       wcsncat,'wcsncat',\
       wcsncmp,'wcsncmp',\
       wcsncpy,'wcsncpy',\
       wcspbrk,'wcspbrk',\
       wcsrchr,'wcsrchr',\
       wcsspn,'wcsspn',\
       wcsstr,'wcsstr',\
       wcstod,'wcstod',\
       wcstok,'wcstok',\
       wcstol,'wcstol',\
       wcstombs,'wcstombs',\
       wcstoul,'wcstoul',\
       wcsxfrm,'wcsxfrm',\
       wctomb,'wctomb',\
       wprintf,'wprintf',\
       wscanf,'wscanf'    
Post 25 Jul 2009, 19:07
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
asmcoder wrote:
2.5 - you can sacrifice 8 bits to write after .


2.5 = 00000010 00000101
LOL Laughing

That's not a 'five', it's 2 and half, so it should be:

00000010 10000000

Laughing

_________________
Previously known as The_Grey_Beast
Post 25 Jul 2009, 19:48
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2141
Location: Estonia
Madis731
I tried finding out how C compilers manage with pow(double,double), but it never inlines it Sad only calls. Where's the source?
Post 25 Jul 2009, 21:32
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
I recall decompiling Intel's or AMD's math library when I was interested in their SIMD trig function approximations, they used some very exotic tricks but I settled on a Taylor series for sine and cosine.

Fanael wrote:
pow(x, y) = exp(ln(x) * y)

This is your best method.

LN(base) using the x87's FYL2X ST(0) = base ST(1) = FLDLN2
EXP(x) using the series EXP(x) = SUM[n=0->INF]( x^n / n! ),
EDIT Too many iterations to get accuracy


Last edited by r22 on 25 Jul 2009, 23:51; edited 1 time in total
Post 25 Jul 2009, 21:47
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Madis, but note that inlining that function every time may be a little bit overkill. The SSE version of it is HUGE, really, it is surprising it is yet faster (haven't checked it really is, I'm just assuming they are not misusing SSE).

To give an idea of how huge it is, when __pow_pentium4 started to be executed I did 180 single steps to return from it (caller was "pow(3, 2.5)").
Post 25 Jul 2009, 21:54
View user's profile Send private message Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael
Maybe this one works:
Code:
fld qword [y] ;size of double is equal to size of qword, isn't it?
fld qword [x]
fyl2x
fld st0
frndint
fsub st1, st0
fxch st1
f2xm1
fld1
faddp st1, st0
fscale
fstp st1    
After that, st0 should contain x^y... Maybe...
Post 25 Jul 2009, 23:20
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
My other option is to sit on 68 bytes of gamma table.
I thought it would be nice by creating it on the fly
this would allow the user to choose gamma factor.
Post 26 Jul 2009, 04:11
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2141
Location: Estonia
Madis731
I also traced it through and couldn't understand what it was doing.
http://jrfonseca.blogspot.com/2008/09/fast-sse2-pow-tables-or-polynomials.html some link I found...

Fanael's code looks okay, but only fails in cases where X is negative for example -0.5^-4 or -0.5^4, but is is easily fixable Smile
EDIT: no, its not simple :S -0.5^1 is negative, -0.5^2 is positive and -0.5^2.1 is invalid

Smile Just make sure that the input is positive and you're set
Post 26 Jul 2009, 08:04
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.