Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1248005

Re: [PATCH v2] ARM: fix vdsomunge not to depend on glibc specific byteswap.h

From "H. Nikolaus Schaller" <hns@goldelico.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2] ARM: fix vdsomunge not to depend on glibc specific byteswap.h
Date 2015-10-15 19:00 +0200
Message-ID <qjU2J-3Ul-3@gated-at.bofh.it> (permalink)
References (1 earlier) <qfBUJ-4pO-1@gated-at.bofh.it> <qjtFf-7cv-11@gated-at.bofh.it> <qjv4m-Wf-7@gated-at.bofh.it> <qjJK4-5GL-27@gated-at.bofh.it> <qjTJo-3xl-21@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Am 15.10.2015 um 18:37 schrieb Russell King - ARM Linux <linux@arm.linux.org.uk>:

> On Thu, Oct 15, 2015 at 07:52:38AM +0200, H. Nikolaus Schaller wrote:
>> ERROR: space prohibited before that close parenthesis ')'
>> #46: FILE: arch/arm/vdso/vdsomunge.c:64:
>> +		(((unsigned short)(x) & (unsigned short)0xff00U) >> 8) ))
> 
> I have a pet hatred of too many parens.  I also have a hatred of idiotic
> casts.  What about changing the above to one of:
> 
> 		(((x) & 0xff00) >> 8)
> 		(((x) >> 8) & 0xff)
> 
>> 
>> ERROR: space prohibited before that close parenthesis ')'
>> #53: FILE: arch/arm/vdso/vdsomunge.c:71:
>> +		(((unsigned int)(x) & (unsigned int)0xff000000UL) >> 24) ))
> 
> and one of:
> 
> 		(((x) & 0xff000000) >> 24)
> 		(((x) >> 24) & 0xff)
> 
> ?

Well, the semantics is sometimes the same but I think readability goes down
because the macro becomes quite un-symmetric and for >> 8 you should
better be sure that values are unsigned if combining with | operator.

Of course it is questionable why the constants (with U and UL modifiers)
are casted.

The full macro (as copied verbatim from existing arch/mips/boot/elf2ecoff.c) is:

+#define swab16(x) \
+	((unsigned short)( \
+		(((unsigned short)(x) & (unsigned short)0x00ffU) << 8) | \
+		(((unsigned short)(x) & (unsigned short)0xff00U) >> 8)))
+
+#define swab32(x) \
+	((unsigned int)( \
+		(((unsigned int)(x) & (unsigned int)0x000000ffUL) << 24) | \
+		(((unsigned int)(x) & (unsigned int)0x0000ff00UL) <<  8) | \
+		(((unsigned int)(x) & (unsigned int)0x00ff0000UL) >>  8) | \
+		(((unsigned int)(x) & (unsigned int)0xff000000UL) >> 24)))
+

I have already submitted a V3 of this patch, so please comment that.

A question is why this is not generally available for all HOSTCC based tools
so that we could simply include some header. But since that is no kernel
code but a tool, I think it is not really necessary to put significant efforts
into this piece of code.

This was probably the intention of the original code to simply include
byteswap.h - then you don't even see how complex the macros are -
but it is not a standard header.

BR and thanks,
Nikolaus Schaller--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH v2] ARM: fix vdsomunge not to depend on glibc specific byteswap.h "H. Nikolaus Schaller" <hns@goldelico.com> - 2015-10-14 14:50 +0200
  Re: [PATCH v2] ARM: fix vdsomunge not to depend on glibc specific  byteswap.h Nathan Lynch <Nathan_Lynch@mentor.com> - 2015-10-14 16:20 +0200
    Re: [PATCH v2] ARM: fix vdsomunge not to depend on glibc specific byteswap.h "H. Nikolaus Schaller" <hns@goldelico.com> - 2015-10-15 08:00 +0200
      Re: [PATCH v2] ARM: fix vdsomunge not to depend on glibc specific  byteswap.h Russell King - ARM Linux <linux@arm.linux.org.uk> - 2015-10-15 18:40 +0200
        Re: [PATCH v2] ARM: fix vdsomunge not to depend on glibc specific byteswap.h "H. Nikolaus Schaller" <hns@goldelico.com> - 2015-10-15 19:00 +0200
      Re: [PATCH v2] ARM: fix vdsomunge not to depend on glibc specific  byteswap.h Nathan Lynch <Nathan_Lynch@mentor.com> - 2015-10-15 19:10 +0200
        Re: [PATCH v2] ARM: fix vdsomunge not to depend on glibc specific byteswap.h "H. Nikolaus Schaller" <hns@goldelico.com> - 2015-10-15 19:20 +0200
          Re: [PATCH v2] ARM: fix vdsomunge not to depend on glibc specific  byteswap.h Nathan Lynch <Nathan_Lynch@mentor.com> - 2015-10-15 19:30 +0200

csiph-web