[riot-notifications] [RIOT-OS/RIOT] gnrc_ipv6_nib/arsm: ensure proper int width in backoff calculation (#10369)

Gaƫtan Harter notifications at github.com
Wed Jan 30 16:33:29 CET 2019


cladmi commented on this pull request.



> @@ -519,7 +519,7 @@ static inline uint32_t _exp_backoff_retrans_timer(uint8_t ns_sent,
 
     /* backoff according to  https://tools.ietf.org/html/rfc7048 with
      * BACKOFF_MULTIPLE == 2 */
-    tmp = ((1 << ns_sent) * retrans_timer * tmp) / US_PER_MS;
+    tmp = ((((uint32_t) 1) << ns_sent) * retrans_timer * tmp) / US_PER_MS;

At first sight I would be thinking that maybe doing a `uint32_t` shift would cost less code.

But it looks like, for a `arduino-atmega2560` that it reduces code size to use `uint64_t` all the way.

```
RIOT_CI_BUILD=1 CFLAGS=-DGNRC_IPV6_NIB_CONF_ARSM=1 USEMODULE=gnrc_ipv6_default BOARD=arduino-mega2560 make -C examples/gnrc_minimal clean all
make: Entering directory '/home/harter/work/git/RIOT/examples/gnrc_minimal'
Building application "gnrc_minimal" for "arduino-mega2560" with MCU "atmega2560".

   text    data     bss     dec     hex filename
  35820     514    2352   38686    971e /home/harter/work/git/RIOT/examples/gnrc_minimal/bin/arduino-mega2560/gnrc_minimal.elf
make: Leaving directory '/home/harter/work/git/RIOT/examples/gnrc_minimal'

# with uint64_t
RIOT_CI_BUILD=1 CFLAGS=-DGNRC_IPV6_NIB_CONF_ARSM=1 USEMODULE=gnrc_ipv6_default BOARD=arduino-mega2560 make -C examples/gnrc_minimal clean all
make: Entering directory '/home/harter/work/git/RIOT/examples/gnrc_minimal'
Building application "gnrc_minimal" for "arduino-mega2560" with MCU "atmega2560".

   text    data     bss     dec     hex filename
  35802     514    2352   38668    970c /home/harter/work/git/RIOT/examples/gnrc_minimal/bin/arduino-mega2560/gnrc_minimal.elf
make: Leaving directory '/home/harter/work/git/RIOT/examples/gnrc_minimal'
```

But on `samr21-xpro` it produces less code to do a `uint32_t` shift:

```
RIOT_CI_BUILD=1 CFLAGS=-DGNRC_IPV6_NIB_CONF_ARSM=1 USEMODULE=gnrc_ipv6_default BOARD=samr21-xpro make -C examples/gnrc_minimal clean all
make: Entering directory '/home/harter/work/git/RIOT/examples/gnrc_minimal'
Building application "gnrc_minimal" for "samr21-xpro" with MCU "samd21".

   text    data     bss     dec     hex filename
  43384     156    7828   51368    c8a8 /home/harter/work/git/RIOT/examples/gnrc_minimal/bin/samr21-xpro/gnrc_minimal.elf
make: Leaving directory '/home/harter/work/git/RIOT/examples/gnrc_minimal'

# with uint64_t
 RIOT_CI_BUILD=1 CFLAGS=-DGNRC_IPV6_NIB_CONF_ARSM=1 USEMODULE=gnrc_ipv6_default BOARD=samr21-xpro make -C examples/gnrc_minimal clean all
make: Entering directory '/home/harter/work/git/RIOT/examples/gnrc_minimal'
Building application "gnrc_minimal" for "samr21-xpro" with MCU "samd21".

   text    data     bss     dec     hex filename
  43400     156    7828   51384    c8b8 /home/harter/work/git/RIOT/examples/gnrc_minimal/bin/samr21-xpro/gnrc_minimal.elf
make: Leaving directory '/home/harter/work/git/RIOT/examples/gnrc_minimal'
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/10369#discussion_r252307276
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190130/6387127a/attachment-0001.html>


More information about the notifications mailing list