Нам бы на авр-ах хоть одно увидеть...
__Dmitry, взял огонь на себя, выходи из боя! Повторяю, выходи из боя!
roboforum.ruТехнический форум по робототехнике. |
|
|
/****************************************
source file containing three math functions. One function performs
addition of two 8-bit numbers, one performs multiplication, and one performs division. The
“main()” function calls each of these functions.
Purpose : Benchmark 8-bit math functions.
****************************************/
typedef unsigned char UInt8;
UInt8 add(UInt8 a, UInt8 b)
{return (a + b);}
UInt8 mul(UInt8 a, UInt8 b)
{return (a * b);}
UInt8 div(UInt8 a, UInt8 b)
{return (a / b);}
void main(void)
{
volatile UInt8 result[4];
result[0] = 12;
result[1] = 3;
result[2] = add(result[0], result[1]);
result[1] = mul(result[0], result[2]);
result[3] = div(result[1], result[2]);
return;
}
;main
;result[0] = 12;
ldi r24, 0x0C
std Y+1, r24
;result[1] = 3;
ldi r24, 0x03
std Y+2, r24
;result[2] = add(result[0], result[1]);
ldd r25, Y+1
ldd r24, Y+2
;return (a + b);
add r24, r25
;result[2] = add(result[0], result[1]);
std Y+3, r24
;result[1] = mul(result[0], result[2]);
ldd r24, Y+1
ldd r25, Y+3
;return (a * b);
mul r25, r24
mov r24, r0
eor r1, r1 ;CLR R1
;result[1] = mul(result[0], result[2]);
std Y+2, r24 ;Store indirect with displacement
;result[3] = div(result[1], result[2]);
ldd r24, Y+2
ldd r22, Y+3
rcall div
std Y+4, r24
;end
div: rcall div_2
ret
div_2:
sub r25, r25
ldi r23, 0x09
rjmp a1
rol r25 ;Rotate Left Through Carry
cp r25,r22 ;Compare
brcs pc+0x02 ;Branch if carry set
sub r25,r22 ;Subtract without carry
a1: rol r24 ;Rotate Left Through Carry
dec r23 ;Decrement
brne pc-0x06 ;Branch if not equal
com r24
ret ;Subroutine return
movlw 0x1
movff PLUSW2, POSTINC1
movff INDF2, POSTINC1
rcall add
movf POSTDEC1, F, ACCESS
movf POSTDEC1, F, ACCESS
movwf INDF1, ACCESS
movlw 0x2
movff INDF1, PLUSW2
add movff FSR2L, POSTINC1
movff FSR1L, FSR2L
movlw 0xfd
movff PLUSW2, POSTINC1
movlw 0xfe
movf PLUSW2, W, ACCESS
movf POSTDEC1, F, ACCESS
addwf INDF1, W, ACCESS
movf POSTDEC1, F, ACCESS
movff INDF1, FSR2L
return
;110 тактов
;21 такт до деления
;main
ldi R28,0xff
ldi R29,0x00
;result[0] = 12;
ldi r24, 0x0C
std Y+1, r24
;result[1] = 3;
ldi r24, 0x03
std Y+2, r24
;result[2] = add(result[0], result[1]);
ldd r25, Y+1
ldd r24, Y+2
;return (a + b);
add r24, r25
;result[2] = add(result[0], result[1]);
std Y+3, r24
;result[1] = mul(result[0], result[2]);
ldd r24, Y+1
ldd r25, Y+3
;return (a * b);
mul r25, r24
mov r24, r0
eor r1, r1 ;CLR R1
;result[1] = mul(result[0], result[2]);
std Y+2, r24 ;Store indirect with displacement
;result[3] = div(result[1], result[2]);
ldd r24, Y+2
ldd r22, Y+3
rcall div
std Y+4, r24
rjmp pc+0
;end
div: sub r25, r25
ldi r23, 0x09
rjmp a1
rol r25 ;Rotate Left Through Carry
cp r25,r22 ;Compare
brcs pc+0x02 ;Branch if carry set
sub r25,r22 ;Subtract without carry
a1: rol r24 ;Rotate Left Through Carry
dec r23 ;Decrement
brne pc-0x06 ;Branch if not equal
com r24
ret ;Subroutine return
;94 такта с div2 (авр библиотека)
;98 тактов с div (микрочип библиотека)
;12 тактов до деления
;result_0 0x0C
;result_1 0xB4
;result_2 0x0F
;result_3 0x0C
LIST P=PIC18F242
INCLUDE P18F242.INC
cblock 8
result_0
result_1
result_2
result_3
LoopCount
REMB0
AARGB0
BARGB0
endc
org 0
bra main
div
;***********************************
; 8 bit unsigned fixed point remainder in REMB0
; Result: AARG, REM <-- AARG / BARG
FXD0808U
clrf REMB0
movlw 0x8
movwf LoopCount
Fxd_1 rlcf AARGB0,F
rlcf REMB0,F
movf BARGB0,W
subwf REMB0,W
bnc Fxd_0
movwf REMB0
incf AARGB0,F
Fxd_0 decfsz LoopCount, F
bra Fxd_1
return
;***********************************
div2 clrf REMB0
movlw 0x9
movwf LoopCount
bra div2_0
div2_1 rlcf REMB0,f
movf BARGB0,W
cpfslt REMB0 ;Compare f with WREG, skip <
subwf REMB0,f
div2_0 rlcf AARGB0,f
decfsz LoopCount, F
bra div2_1
return
;***********************************
main
;result[0] = 12;
movlw 0xc
movwf result_0
;result[1] = 3;
movlw 0x3
movwf result_1
;result[2] = add(result[0], result[1]);
movf result_0,w
addwf result_1,w
movwf result_2
;result[1] = mul(result[0], result[2]);
movf result_0,w
mulwf result_2
movff PRODL,result_1
;result[3] = div(result[1], result[2]);
movff result_1,AARGB0
movff result_2,BARGB0
rcall div2
movff AARGB0,result_3
bra $
end
;48 тактов
.equ __24F04KA201, 1
.include "p24F04KA201.inc"
.global __reset ;The label for the first line of code
.bss
result_0: .space 8
.text
__reset:
;------------------------------------------------------------------------------
;Initialize stack pointer and limit register
mov #__SP_init, W15 ;Initalize the Stack Pointer register
mov #__SPLIM_init, W0 ;Get address at the end of stack space
mov W0, SPLIM ;Load the Stack Pointer Limit register
nop ;Add NOP to follow SPLIM initialization
;------------------------------------------------------------------------------
mov #result_0,w14
;result[0] = 12;
mov.b #0xc,w0
mov.b w0,[w14]
;result[1] = 3;
mov.b #0x3,w0
mov.b w0,[w14+1]
;result[2] = add(result[0], result[1]);
mov.b [w14+1],w1
add.b w0,[w14],w0
mov.b w0,[w14+2]
;result[1] = mul(result[0], result[2]);
mov.b [w14+2],w1
mov.b [w14],w0
mul.ss w1,w0,w0
; ze w0,w0
mov.b w0,[w14+1]
;result[3] = div(result[1], result[2]);
mov.b [w14+1],w1
mov.b [w14+2],w2
rcall div
mov.b w0,[w14+3]
bra $
div: ze w1,w1
ze w2,w2
repeat #17
div.uw w1,w2
ze w0,w0
return
.end
Dmitry__ писал(а):на делении авр сократил отставание, пик 94, авр 110
=DeaD= писал(а):Что быстрее то в итоге в абсолютных цифрах и при каких условиях?
Michael_K писал(а):Это в микросекундах сколько?
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 16