XC8 Optimalizace 2, proc nefunguje spravne v preruseni.
Ondřej Janovský
ondrej.janovsky na alarex.cz
Středa Listopad 3 13:54:22 CET 2021
A ještě pěkné předvedení:
https://stackoverflow.com/a/21297642
Oja
Dne 03. 11. 21 v 13:51 Ondřej Janovský napsal(a):
> Mě pomohlo magické volatile .
>
> https://stackoverflow.com/a/31996980
>
> Oja
>
> Dne 03. 11. 21 v 13:29 Libor Konečný napsal(a):
>> Zdravim odborniky na kompilator XC8 a prosim o posledni radu.
>>
>> Presel jsem na nej kratce z pocatecnim nadsenim, ale nyni me
>> zarazila optimalizace.
>>
>>
>> Pokud ji mam nastaveno na 1 (tzn vyhodi z kodu jen nepouzivane
>> funkce) tak kod (nize funguje) ale s optimalizaci 2 , ktera kod
>> upravuje mi to nefunguje.
>>
>> Mam v interruptu mimojine tuto funkci:
>>
>> if (intrbyte==xBTCON1[bt1_pos]) {bt1_pos++; } else bt1_pos=0;
>> if (bt1_pos==14) {
>> bt1_pos=0;
>> BT_conrequest=1;
>> }
>>
>> fillRXFIFO[idx++]=intrbyte;
>>
>> v xBTcon1 je RAm retezec, intrbyte je byte zachyceny z preruseni UARTU.
>>
>> FillRSFIFO je pole do ktereho se uklada vsehcno a jedou za cas se
>> precte.
>>
>> Tedy snazim se odcyhtit se dany retezec a pokud se vyskytne nastavi
>> promennou BT_conrequest=1
>>
>> Pri mensim kodu (cca 90KB) to fungovalo, nyni pri 124KB (z celkovych
>> 131KB) se to chova tragicky.
>>
>> A to tak, ze retezec prijde (na 100%) ale BT_connreqest se nenastavi.
>>
>> Je zahadou ze kdyz prectu pole fillRXFIFO, tak v nem sew retezec
>> nachaci.
>>
>> Pri optimalicaci 1 to funguje, pri optimalizaci 2 to funguje jen pri
>> mensim kodu.
>>
>> Uvadim asm list s optimalizaci 1
>>
>> if (intrbyte==xBTCON1[bt1_pos]) {bt1_pos+
>> + +; } else bt1_pos=0;
>> 95991 01AEE4 0E78 movlw low _xBTCON1
>> 95992 01AEE6 2528 addwf _bt1_pos& (0+255),w,b
>> 95993 01AEE8 6ED9 movwf fsr2l,c
>> 95994 01AEEA 6ADA clrf fsr2h,c
>> 95995 01AEEC 0E06 movlw high _xBTCON1
>> 95996 01AEEE 22DA addwfc fsr2h,f,c
>> 95997 01AEF0 5192 movf _intrbyte& (0+255),w,b
>> 95998 01AEF2 18DE xorwf postinc2,w,c
>> 95999 01AEF4 A4D8 btfss status,2,c
>> 96000 01AEF6 D002 goto i2l41145
>> 96001
>> 96002 ; BSR set to: 2
>> 96003 01AEF8 2B28 incf _bt1_pos& (0+255),f,b
>> 96004 01AEFA D002 goto i2l41147
>> 96005 01AEFC i2l41145:
>> 96006
>> 96007 ; BSR set to: 2
>> 96008 01AEFC 0E00 movlw 0
>> 96009 01AEFE 6F28 movwf _bt1_pos& (0+255),b
>> 96010 01AF00 i2l41147:
>> 96011
>> 96012 ; BSR set to: 2
>> 96013 ;main.c: 3051: if (bt1_pos==14)
>> {bt1_pos=0;
>> 96014 01AF00 0E0E movlw 14
>> 96015 01AF02 1928 xorwf _bt1_pos& (0+255),w,b
>> 96016 01AF04 A4D8 btfss status,2,c
>> 96017 01AF06 D004 goto i2l41151
>>
>>
>> A s optimalizaci 2
>>
>> if (intrbyte==xBTCON1[bt1_pos]) {bt1_pos++; } else bt1_pos=0;
>> 95092 01A8E2 0E8C movlw low _xBTCON1
>> 95093 01A8E4 0102 movlb 2 ; () banked
>> 95094 01A8E6 252A addwf _bt1_pos& (0+255),w,b
>> 95095 01A8E8 6ED9 movwf fsr2l,c
>> 95096 01A8EA 6ADA clrf fsr2h,c
>> 95097 01A8EC 0E06 movlw high _xBTCON1
>> 95098 01A8EE 22DA addwfc fsr2h,f,c
>> 95099 01A8F0 0101 movlb 1 ; () banked
>> 95100 01A8F2 51F4 movf _intrbyte& (0+255),w,b
>> 95101 01A8F4 18DE xorwf postinc2,w,c
>> 95102 01A8F6 A4D8 btfss status,2,c
>> 95103 01A8F8 D003 goto i2l59157
>> 95104
>> 95105 ; BSR set to: 1
>> 95106 01A8FA 0102 movlb 2 ; () banked
>> 95107 01A8FC 2B2A incf _bt1_pos& (0+255),f,b
>> 95108 01A8FE D003 goto i2l59159
>> 95109 01A900 i2l59157:
>> 95110
>> 95111 ; BSR set to: 1
>> 95112 01A900 0E00 movlw 0
>> 95113 01A902 0102 movlb 2 ; () banked
>> 95114 01A904 6F2A movwf _bt1_pos& (0+255),b
>> 95115 01A906 i2l59159:
>> 95116
>> 95117 ; BSR set to: 2
>> 95118 ;main.c: 2992: if (bt1_pos==14)
>> {bt1_pos=0;
>> 95119 01A906 0E0E movlw 14
>> 95120 01A908 192A xorwf _bt1_pos& (0+255),w,b
>> 95121 01A90A A4D8 btfss status,2,c
>> 95122 01A90C D004 goto i2l59163
>> 95123
>>
>>
>>
>> Rozdil je v pridani movlb 2 (asi pouzivani RAM banky 2)
>>
>> Otazka je proc to nechce spilnit tu podminku if
>> (intrbyte==xBTCON1[bt1_pos]
>>
>>
>> Delam neco spatne, nebo se mam smirit s kodem bez optimalizace ?
>>
>> Diky moc
>>
>> LK
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> HW-list mailing list - sponsored by www.HW.cz
>> Hw-list na list.hw.cz
>> http://list.hw.cz/mailman/listinfo/hw-list
>
>
> _______________________________________________
> HW-list mailing list - sponsored by www.HW.cz
> Hw-list na list.hw.cz
> http://list.hw.cz/mailman/listinfo/hw-list
Další informace o konferenci Hw-list