Notice: We have migrated to GitLab launching 2024-05-01 see here: https://gitlab.rtems.org/

#1955 closed defect (fixed)

Fix CPU_swap_u16

Reported by: seb Owned by: Joel Sherrill
Priority: normal Milestone: 4.11
Component: score Version: 4.11
Severity: normal Keywords:
Cc: Blocked By:
Blocking:

Description

(from Werner Almesberger)
CPU_swap_u16 is a macro, with all the problems that entails,
such as:

  • multiple evaluation of the argument,
  • tricky type semantics, and last but not least
  • the need to protect arguments

The lack of the latter is a bug, though I don't think it had any
real-life impact on M1 behaviour this far.

Converting this to an inline function solves all these issues.

  • Werner

Index: cpukit/score/cpu/lm32/rtems/score/cpu.h
===================================================================
RCS file: /usr1/CVS/rtems/cpukit/score/cpu/lm32/rtems/score/cpu.h,v
retrieving revision 1.14
diff -u -r1.14 cpu.h
--- cpukit/score/cpu/lm32/rtems/score/cpu.h 27 Sep 2011 09:17:02 -0000 1.14
+++ cpukit/score/cpu/lm32/rtems/score/cpu.h 8 Nov 2011 18:27:45 -0000
@@ -1258,8 +1258,10 @@

  • @param[in] value is the value to be swapped
  • @return the value after being endian swapped */

-#define CPU_swap_u16( value ) \

  • (((value&0xff) << 8) | ((value >> 8)&0xff))

+static inline uint16_t CPU_swap_u16(uint16_t v)
+{
+ return v << 8 | v >> 8;
+}

#ifdef cplusplus
}

Change History (2)

comment:1 Changed on 11/09/11 at 14:16:54 by Joel Sherrill

Resolution: fixed
Status: newclosed

Added to 4.10 branch and head.

Closing. Thanks.

comment:2 Changed on 11/24/14 at 18:58:28 by Gedare Bloom

Version: HEAD4.11

Replace Version=HEAD with Version=4.11 for the tickets with Milestone >= 4.11

Note: See TracTickets for help on using tickets.