-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core: Add compile time byte swapping (C11 version) #5453
Conversation
To convert the supplied argument HTONL and friends will use a simple formula instead of a function call, iff the value of the argument is known at compile time. This enables the use in enum definitions such as: ```c typedef enum { A = CT_HTONS(0x0001), AAAA = CT_HTONS(0x001C), } dns_query_type; ``` Closes: #3812
Major tag because of |
I don't get what this macro does... @DipSwitch's code on the other hand I understand. Also what is with |
Clang supports generic selections since somewhen in 2012. Source: some blog that comes up if you google "clang generic selection". |
The macro "selects" either It uses the type deduction in: 1 ? (char*) 0 : (void*) (ptrdiff_t) ((EXPR) - (EXPR)) If the value of |
The biggest issue is probably the msp430 platforms which are currently stuck at gcc 4.6 for most users. The other platforms will likely be at 4.9 or later anytime soon because of good upstream support for the ports. |
Hm, I thought a |
Interesting :), I'll soon give it a try :) |
Won't make it for release because of missing msp430 support |
else | ||
ifeq ($(shell $(CC) -std=c99 -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0) | ||
CFLAGS += -std=c99 | ||
CFLAGS += -std=c11 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errrrr... portability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mlenders@sarajevo RIOT]<3 msp430-gcc --version
msp430-gcc (GCC) 4.6.3 20120301 (mspgcc LTS 20120406 unpatched)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Compare GCC wiki
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read the comments in this PR ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyhow, this first checks for c99 and if successful, sets c11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry for the noise... But up until this is resolved I would prefer the portable version at #3812.
Okay it seems we progressed with c11 anyway, but the byteorder functions changed a little bit (they are now lower-case). @DipSwitch do you want to keep the upper-case variant for constant initialization (would be like we do with most other data types too). And after all: needs rebase. |
needs rebase, but also discussion seems inconclusive, and was postponed several times now. Remove milestone, for time being. |
@miri64 do you see a chance to progress this? Or shall we close? |
No real progress for >1 year, so I would say close. If someone disagrees, please don't hesitate reopen. |
Please see #4812 first.
Using C11 you can tell the the value of an expression is known at compile:
This PR uses this feature to optimize HTONL and friends. They'll use shift-and-or if the value is known at compile time, otherwise
__builtin_bswap…()
.Drawback:
_Generic
needs C11 and is only implemented since GCC 4.9.