#avr Logs

Aug 18 2018

#avr Calendar

12:31 PM [1]MrMobius is now known as MrMobius
12:36 PM Jan-: hi guys
12:36 PM Jan-: is there any quick way to test, in c, if an add of two 8 bit numbers overflowed?
12:37 PM Jan-: I guess the avr itself has a flag for that but I'm not sure if I can use it in that way
12:40 PM MrMobius: Jan-, can you promote to 16 bit and check the 9th bit?
12:40 PM MrMobius: or just do a > comparison
12:40 PM Jan-: I basically just have to check if value_now < value_then we overflowed
12:40 PM Jan-: but I just know that the AVR has a flag for it
12:40 PM Jan-: I wondered if I could check that flag
12:40 PM Jan-: in asm I guess I could
12:41 PM MrMobius: why would you do that? to be faster than >?
12:42 PM Jan-: Idle curiosity really
12:42 PM Jan-: I guess it would be faster
12:42 PM MrMobius: how do you think it knows if it is larger when you use >?
12:43 PM Jan-: depends on how the compiler puts it together I guess
12:43 PM MrMobius: true
12:43 PM MrMobius: but the short answer is that it checks the flag
12:43 PM Jan-: I assume there is an 8 bit magnitude comparator built out of gates in the avr's cpu somewhere.
12:44 PM Jan-: I know a 4 bit one is like 15 gates
12:47 PM MrMobius: Jan-, I just mean you could do asm and check the flag yourself but when you do < in C the compiler produces asm that checks the flag, so you may not get any speed up by doing it yourself.
12:47 PM MrMobius: in fact, you may do it slower than the compiler
12:48 PM Jan-: well hang on, it can't do greater than or less than comparisons by checking the carry flag
12:48 PM MrMobius: if you are really curious, you could look at what the compiler is generating for < and modify it to see if you can do better
12:48 PM MrMobius: modify the compiler output i mean
12:51 PM MrMobius: how about the overflow flag V?
12:51 PM MrMobius: look on page 21 here http://ww1.microchip.com/downloads/en/devicedoc/atmel-0856-avr-instruction-set-manual.pdf