avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] Re: [avr-libc-commit] [2158] Submitted by Jan Waclawek:


From: Wouter van Gulik
Subject: [avr-libc-dev] Re: [avr-libc-commit] [2158] Submitted by Jan Waclawek:
Date: Thu, 10 Jun 2010 22:25:12 +0200
User-agent: Thunderbird 2.0.0.24 (Windows/20100228)

Joerg Wunsch schreef:

+
+\code
+#define cli() __asm volatile( "cli" ::: "memory" )
+#define sei() __asm volatile( "sei" ::: "memory" )
+
+unsigned int ivar;
+
+void test2( unsigned int val )
+{
+  val = 65535U / val;
+
+  cli();
+
+  ivar = val;
+
+  sei();
+}
+\endcode
+
+compiles with optimisations switched on (-Os) to
+
+\verbatim
+00000112 <test2>:
+ 112:  bc 01           movw    r22, r24
+ 114:  f8 94           cli
+ 116:  8f ef           ldi     r24, 0xFF       ; 255
+ 118:  9f ef           ldi     r25, 0xFF       ; 255
+ 11a:  0e 94 96 00     call    0x12c   ; 0x12c <__udivmodhi4>
+ 11e:  70 93 01 02     sts     0x0201, r23
+ 122:  60 93 00 02     sts     0x0200, r22
+ 126:  78 94           sei
+ 128:  08 95           ret
+\endverbatim
+
+where the potentially slow multiplication is moved across cli(),
+resulting in interrupts to be disabled longer than intended.
There is "typo", the texts talks about multiplication instead of divide.

HTH,

Wouter




reply via email to

[Prev in Thread] Current Thread [Next in Thread]