这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » I2c,GCC 做I2c感受到GCC的效率啊

共3条 1/1 1 跳转至

I2c,GCC 做I2c感受到GCC的效率啊

院士
2006-09-17 18:14:16     打赏
I2c,GCC 做I2c感受到GCC的效率啊



关键词: 受到     效率    

院士
2006-12-22 22:43:00     打赏
2楼
问 分别用GCC和ICC编译相同的一段程序,我编译的是I2c的中断程序.ICC手头上有正版,打勾了Enable Code Compression,GCC的优化参数是默认的Os.

GCC:
    if (twst == TW_SR_SLA_ACK)
  c4:    c0 36           cpi    r28, 0x60    ; 96
  c6:    61 f0           breq    .+24         ; 0xe0
    {
        TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA)|(1<<TWIE);
    }
    else if (twst == TW_SR_DATA_ACK)
  c8:    c0 38           cpi    r28, 0x80    ; 128
  ca:    51 f0           breq    .+20         ; 0xe0
        TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA)|(1<<TWIE);
    }
    else if (twst == TW_SR_STOP)
  cc:    c0 3a           cpi    r28, 0xA0    ; 160
  ce:    41 f0           breq    .+16         ; 0xe0
    {
        TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA)|(1<<TWIE);
    }
    else if (twst == TW_ST_SLA_ACK)
  d0:    c8 3a           cpi    r28, 0xA8    ; 168
  d2:    11 f0           breq    .+4          ; 0xd8
    {
        TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWIE);    
    }
    else if (twst == TW_ST_DATA_ACK)
  d4:    c8 3b           cpi    r28, 0xB8    ; 184
  d6:    11 f4           brne    .+4          ; 0xdc
    {
        TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWIE);
  d8:    85 e8           ldi    r24, 0x85    ; 133
  da:    03 c0           rjmp    .+6          ; 0xe2
    }    
    else if (twst == TW_ST_DATA_NACK)
  dc:    c0 3c           cpi    r28, 0xC0    ; 192
  de:    11 f4           brne    .+4          ; 0xe4
    {
        TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA)|(1<<TWIE);
  e0:    85 ec           ldi    r24, 0xC5    ; 197
  e2:    86 bf           out    0x36, r24    ; 54
    }

ICC:
(0039)     if (tmpchr == TW_SR_SLA_ACK)
    0050 3640      CPI    R20,0x60
    0051 F419      BNE    0x0055
(0040)     {
(0041)         TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA)|(1<<TWIE);
    0052 EC85      LDI    R24,0xC5
    0053 BF86      OUT    P36,R24
(0042)     }
    0054 C018      RJMP    0x006D
(0043)     else if (tmpchr == TW_SR_DATA_ACK)
    0055 3840      CPI    R20,0x80
    0056 F419      BNE    0x005A
(0044)     {
(0068)         TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA)|(1<<TWIE);
    0057 EC85      LDI    R24,0xC5
    0058 BF86      OUT    P36,R24
(0069)     }
    0059 C013      RJMP    0x006D
(0070)     else if (tmpchr == TW_SR_STOP)
    005A 3A40      CPI    R20,0xA0
    005B F419      BNE    0x005F
(0071)     {
(0076)         TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA)|(1<<TWIE);
    005C EC85      LDI    R24,0xC5
    005D BF86      OUT    P36,R24
(0077)     }
    005E C00E      RJMP    0x006D
(0078)     else if (tmpchr == TW_ST_SLA_ACK)
    005F 3A48      CPI    R20,0xA8
    0060 F419      BNE    0x0064
(0079)     {
(0083)         TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWIE);    
    0061 E885      LDI    R24,0x85
    0062 BF86      OUT    P36,R24
(0084)     }
    0063 C009      RJMP    0x006D
(0085)     else if (tmpchr == TW_ST_DATA_ACK)
    0064 3B48      CPI    R20,0xB8
    0065 F419      BNE    0x0069
(0086)     {
(0087)         TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWIE);
    0066 E885      LDI    R24,0x85
    0067 BF86      OUT    P36,R24
(0088)     }    
    0068 C004      RJMP    0x006D
(0089)     else if (tmpchr == TW_ST_DATA_NACK)
    0069 3C40      CPI    R20,0xC0
    006A F411      BNE    0x006D
(0090)     {
(0091)         TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA)|(1<<TWIE);
    006B EC85      LDI    R24,0xC5
    006C BF86      OUT    P36,R24
(0092)     }

其中省略掉了//注释掉的处理程序.
在ICC中,可能测试程序不长,看不到选与不选Enable那项有和不同,但与GCC相比教,明显的编译后的汇编程序ICC不如GCC来简单.感觉GCC比较聪敏.:) ICC的处理就象按部就班的样子,太老实!
1: 我试过:GCC的优化确实不错,接近汇编哦........

专家
2023-03-11 11:57:22     打赏
3楼

学习


共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]