• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Re: 請教PIC除法運算時所耗的週期數?
#10
版主
版主


查看用戶資訊
我想應該沒有人可以看的出來 C 程式所花的執行時間吧 ! 就算是轉成組合語言一個迴圈就不好算了。
一般 PIC 的使用者大都是使用 MPLAB SIM 裡的 Stopwatch 配合斷點的設定來量程式執行的時間。

發表於: 2009/2/27 18:24
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教PIC除法運算時所耗的週期數?
#9
新會員
新會員


查看用戶資訊
不好意思,問個題外問題,如何看某段程式碼需要多少cpu cycle呢??

發表於: 2009/2/27 17:35
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教PIC除法運算時所耗的週期數?
#8
資深會員
資深會員


查看用戶資訊
google又多一個結果了可用了。



/*

* Prototypes for non-standard maths functions; these are part of libm

* and will be satisfied by libm-<omf>.a which is automatically included

* by the compiler.

*/



unsigned long __udiv3216(unsigned long, unsigned int);

long __div3216(long, int);



#endif

發表於: 2009/2/27 11:54
The Answer to Life, the Universe, and Everything.
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教PIC除法運算時所耗的週期數?
#7
版主
版主


查看用戶資訊
有的,在 MPLAB® C COMPILER FOR PIC24 MCUs AND dsPIC® DSCs USER’S GUIDE 裡的附錄 B 裡有詳細的說明與使用範例。User's Guide 在 C:\Program Files\Microchip\MPLAB C30\docs在

Built-In Function List
__builtin_addab     __builtin_movsac     __builtin_tbloffset
__builtin_add         __builtin_mpy         __builtin_tblrdh
__builtin_btg         __builtin_mpyn         __builtin_tblrdl
__builtin_clr         __builtin_msc         __builtin_tblwth
__builtin_clr_prefetch     __builtin_mulss     __builtin_tblwtl
__builtin_divf         __builtin_mulsu     __builtin_write_NVM
__builtin_divmodsd     __builtin_mulus     __builtin_write_OSCCONL
__builtin_divmodud     __builtin_muluu     __builtin_write_OSCCONH
__builtin_divsd     __builtin_nop         __builtin_write_RTCWEN
__builtin_divud     __builtin_psvpage
__builtin_dmaoffset     __builtin_psvoffset
__builtin_ed         __builtin_readsfr
__builtin_edac         __builtin_return_address
__builtin_fbcl         __builtin_sac
__builtin_lac         __builtin_sacr
__builtin_mac         __builtin_sftac
__builtin_modsd     __builtin_subab
__builtin_modud     __builtin_tblpage

發表於: 2009/2/27 8:26
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教PIC除法運算時所耗的週期數?
#6
版主
版主


查看用戶資訊
明天到公司後我在來找 builtin 的支援項目,家裡電腦沒裝 C30

發表於: 2009/2/26 21:42

Edited by Ryang on 2009年02月27日 08:20:02
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教PIC除法運算時所耗的週期數?
#5
資深會員
資深會員


查看用戶資訊
Microchip有提供這方面的函式庫,但是找不到文件有提到這方面的事。
只在 Release Notes 中提一下,與原廠的討論區出現過一次。


請打開放程式集的目錄下方

%PROGRAMFILES%\Microchip\MPLAB C30\include\math.h

最後幾行的地方自已研究看看,應該就是您想要的東西。

發表於: 2009/2/26 16:59
The Answer to Life, the Universe, and Everything.
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教PIC除法運算時所耗的週期數?
#4
版主
版主


查看用戶資訊
當然一般的 ANSI C 在編譯的過程對一些專屬的特殊指令Defult 是不會使用的,像 DSP 計算,repaet, div 等,這些需用組語方式特別去指定運算。C30 有提供較簡單的方式可以用 builtin 的巨集來解決。
32-bit/16-bit 的用法如下:

__builtin_divsd(const long num, const int den)

發表於: 2009/2/26 10:30
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教PIC除法運算時所耗的週期數?
#3
新會員
新會員


查看用戶資訊
參照:

Ryang 寫道:
浮點運算因為不是 Float-Point Processor 所以一定要用很多的組語去寫所以要花掉很多的時間。但是整數的32/16 bit 的除法,有組語的指令支援,基本上除法指令配合 Repeat #17 總共要花掉 18 Tcy,所以整數除法與浮點數就執行時間上是差的很多。

如果 C 資料型別改成 int ?
編譯過後看一下 LST Window 到底是用何種方式在做除法,如果不行就要使用 #built-in 的方式或 In-Line Assembly 方式來處理。



Dear 版主 :

我有去試過,C資料型別改成int型態,所花費的cycle也是一樣長。而且for我的應用,C變數有可能會超過16bit的,不能採用int型態。

BTW,稍微看了一下它編譯出來的code,用的都是加、減、乘、移位…等指令,似乎都沒有用到"DIV"這個指令?

誠心請教,如果用 Assembly寫 (long)C = (long)A / (int)B,該怎麼寫?小弟剛接觸pic不久,又不太熟悉組語,能不能幫忙編寫 這一行 32bit除以16bit 的組語code? 讓小弟學習一下?

(A,B,C,三變數都有可能為負數)

感激不盡,謝謝!

發表於: 2009/2/25 18:13
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教PIC除法運算時所耗的週期數?
#2
版主
版主


查看用戶資訊
浮點運算因為不是 Float-Point Processor 所以一定要用很多的組語去寫所以要花掉很多的時間。但是整數的32/16 bit 的除法,有組語的指令支援,基本上除法指令配合 Repeat #17 總共要花掉 18 Tcy,所以整數除法與浮點數就執行時間上是差的很多。

如果 C 資料型別改成 int ?
編譯過後看一下 LST Window 到底是用何種方式在做除法,如果不行就要使用 #built-in 的方式或 In-Line Assembly 方式來處理。

發表於: 2009/2/20 17:31
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請教PIC除法運算時所耗的週期數?
#1
新會員
新會員


查看用戶資訊
Dear All :

我check了一下spec,PIC24做浮點數除法運算時,在400個cycle內,如果做32bit/16bit的整數除法運算只要20個cycle內。

我做了下面的簡單程式 :

long A = 55555555 ;
int B = 100 ;
long C ;

C = A/B ;

不知道為什麼在上面這行指令要佔400個cycle?

有沒有辦法可以縮短運算的周期呢? 還請幫忙指教,謝謝!

發表於: 2009/2/20 12:39
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------