Re: 請教PIC除法運算時所耗的週期數?
|
||||
---|---|---|---|---|
版主
|
我想應該沒有人可以看的出來 C 程式所花的執行時間吧 ! 就算是轉成組合語言一個迴圈就不好算了。
一般 PIC 的使用者大都是使用 MPLAB SIM 裡的 Stopwatch 配合斷點的設定來量程式執行的時間。
發表於: 2009/2/27 18:24
|
|||
|
Re: 請教PIC除法運算時所耗的週期數?
|
||||
---|---|---|---|---|
新會員
|
不好意思,問個題外問題,如何看某段程式碼需要多少cpu cycle呢??
發表於: 2009/2/27 17:35
|
|||
|
Re: 請教PIC除法運算時所耗的週期數?
|
||||
---|---|---|---|---|
版主
|
有的,在 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
發表於: 2009/2/27 8:26
|
|||
|
Re: 請教PIC除法運算時所耗的週期數?
|
||||
---|---|---|---|---|
版主
|
明天到公司後我在來找 builtin 的支援項目,家裡電腦沒裝 C30
發表於: 2009/2/26 21:42
Edited by Ryang on 2009年02月27日 08:20:02
|
|||
|
Re: 請教PIC除法運算時所耗的週期數?
|
||||
---|---|---|---|---|
資深會員
|
Microchip有提供這方面的函式庫,但是找不到文件有提到這方面的事。
只在 Release Notes 中提一下,與原廠的討論區出現過一次。 請打開放程式集的目錄下方 %PROGRAMFILES%\Microchip\MPLAB C30\include\math.h 最後幾行的地方自已研究看看,應該就是您想要的東西。
發表於: 2009/2/26 16:59
|
|||
The Answer to Life, the Universe, and Everything.
|
||||
|
Re: 請教PIC除法運算時所耗的週期數?
|
||||
---|---|---|---|---|
版主
|
當然一般的 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
|
|||
|
Re: 請教PIC除法運算時所耗的週期數?
|
||||
---|---|---|---|---|
新會員
|
參照:
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
|
|||
|
Re: 請教PIC除法運算時所耗的週期數?
|
||||
---|---|---|---|---|
版主
|
浮點運算因為不是 Float-Point Processor 所以一定要用很多的組語去寫所以要花掉很多的時間。但是整數的32/16 bit 的除法,有組語的指令支援,基本上除法指令配合 Repeat #17 總共要花掉 18 Tcy,所以整數除法與浮點數就執行時間上是差的很多。
如果 C 資料型別改成 int ? 編譯過後看一下 LST Window 到底是用何種方式在做除法,如果不行就要使用 #built-in 的方式或 In-Line Assembly 方式來處理。
發表於: 2009/2/20 17:31
|
|||
|
請教PIC除法運算時所耗的週期數?
|
||||
---|---|---|---|---|
新會員
|
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
|
|||
|