Topic: Two small feature requests
Author: cooky451@gmail.com
Date: Sun, 16 Dec 2012 21:10:39 -0800 (PST)
Raw View
------=_Part_291_29855935.1355721039015
Content-Type: text/plain; charset=ISO-8859-1
Hi,
I think this two features could help a lot of programmers out:
1. Compile time endianness checking. As far as I know, there's no way to do
that right now, even with constexpr. (The usual method is casting a
uint16_t* to a uint8_t* and checking it's value.) With the C++ approach to
do many things at compile time, this information could be extremely helpful
to some low-level algorithms. (e.g. SHA-2) I also think the compiler has
this information anyway, since he has to put constant values in memory.
(int i = 12345, layout for 12345 must be known at compile time. ?) This
could be done by just setting some enum std::platform_endianness.
2. Overflow-checks. While many (most?) CPUs have some kind of
carry/overflow bit, getting the compiler to actually use this information
doesn't seem straight forward or even possible for all cases to me. The
usual C++ approach is to use some arithmetic "tricks" to figure out if an
operation would overflow or not. In most cases this seems to be much slower
than just using the dedicated CPU flags. With library functions like
bool std::safe_multiply(uint32_t a, uint32_t b, uint32_t& c)
bool std::safe_multiply(int32_t a, int32_t b, int32_t& c) // State of c
is implementation-/undefined if function returns false
// Add functions for addition etc., for all integer types.
the implementation could actually use the scope of the platform to provide
optimal performance in a standard conforming way. I think this feature
could be very useful for things like safe_int or unsigned_integer<uint64_t,
8> (arbitrary precision).
Okay, now have fun destroying me. :)
--
------=_Part_291_29855935.1355721039015
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hi, <br><br>I think this two features could help a lot of programmers out:<=
br><br>1. Compile time endianness checking. As far as I know, there's no wa=
y to do that right now, even with constexpr. (The usual method is casting a=
uint16_t* to a uint8_t* and checking it's value.) With the C++ approach to=
do many things at compile time, this information could be extremely helpfu=
l to some low-level algorithms. (e.g. SHA-2) I also think the compiler has =
this information anyway, since he has to put constant values in memory. (in=
t i =3D 12345, layout for 12345 must be known at compile time. ?) This coul=
d be done by just setting some enum std::platform_endianness.<br><br>2. Ove=
rflow-checks. While many (most?) CPUs have some kind of carry/overflow bit,=
getting the compiler to actually use this information doesn't seem straigh=
t forward or even possible for all cases to me. The usual C++ approach is t=
o use some arithmetic "tricks" to figure out if an operation would overflow=
or not. In most cases this seems to be much slower than just using the ded=
icated CPU flags. With library functions like<br><br> bool std::safe_=
multiply(uint32_t a, uint32_t b, uint32_t& c) <br> bool std::safe=
_multiply(int32_t a, int32_t b, int32_t& c) // State of c is implementa=
tion-/undefined if function returns false<br>// Add functions for addition =
etc., for all integer types.<br><br>the implementation could actually use t=
he scope of the platform to provide optimal performance in a standard confo=
rming way. I think this feature could be very useful for things like safe_i=
nt or unsigned_integer<uint64_t, 8> (arbitrary precision).<br><br>Oka=
y, now have fun destroying me. :)<br>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_291_29855935.1355721039015--
.
Author: Beman Dawes <bdawes@acm.org>
Date: Mon, 17 Dec 2012 10:00:25 -0500
Raw View
On Mon, Dec 17, 2012 at 12:10 AM, <cooky451@gmail.com> wrote:
> Hi,
>
> I think this two features could help a lot of programmers out:
>
> 1. Compile time endianness checking. As far as I know, there's no way to do
> that right now, even with constexpr. (The usual method is casting a
> uint16_t* to a uint8_t* and checking it's value.) With the C++ approach to
> do many things at compile time, this information could be extremely helpful
> to some low-level algorithms. (e.g. SHA-2) I also think the compiler has
> this information anyway, since he has to put constant values in memory. (int
> i = 12345, layout for 12345 must be known at compile time. ?) This could be
> done by just setting some enum std::platform_endianness.
My guess is that a well thought out endianness proposal would sail
through the committee.
Think about how the standard already specifies such things. It's an
implementation property. So the target would like be <limits>, and
C++14.
Perhaps something like:
constexpr endian endianness() noexcept;
Where endian is an enum class with big, little, and possibly some
others defined.
Figure out how to handle odd-ball endianness. Maybe allow endian to
have an additional implementation defined member if the endianness
isn't big or little.
Write a proposal. The committee is an all volunteer organization. If
you don't volunteer to write the proposal, it is doubtful anyone else
will step forward.
In the proposal, don't speculate on how such a function might be
implemented, other than saying it might require compiler support. Do
mention the many times similar features have been implemented, usually
by macros such as in the Boost endian.hpp header.
Send me the proposal. I'll get a number assigned and champion it
before the committee. Or show up at the next meeting (Bristol, UK, in
April) and champion it yourself:-)
--Beman
--
.
Author: Bjorn Reese <breese@mail1.stofanet.dk>
Date: Mon, 17 Dec 2012 16:24:27 +0100
Raw View
On 2012-12-17 06:10, cooky451@gmail.com wrote:
> 1. Compile time endianness checking. As far as I know, there's no way to
> do that right now, even with constexpr. (The usual method is casting a
> uint16_t* to a uint8_t* and checking it's value.) With the C++ approach
Sometimes endianness can only be detected correctly at run-time. See
http://sourceforge.net/p/predef/wiki/Endianness/
--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Mon, 17 Dec 2012 17:24:46 +0200
Raw View
--e89a8ff1c6c838784704d10dfb1c
Content-Type: text/plain; charset=ISO-8859-1
On Dec 17, 2012 5:00 PM, "Beman Dawes" <bdawes@acm.org> wrote:
>
> On Mon, Dec 17, 2012 at 12:10 AM, <cooky451@gmail.com> wrote:
> > Hi,
> >
> > I think this two features could help a lot of programmers out:
> >
> > 1. Compile time endianness checking. As far as I know, there's no way
to do
> > that right now, even with constexpr. (The usual method is casting a
> > uint16_t* to a uint8_t* and checking it's value.) With the C++ approach
to
> > do many things at compile time, this information could be extremely
helpful
> > to some low-level algorithms. (e.g. SHA-2) I also think the compiler has
> > this information anyway, since he has to put constant values in memory.
(int
> > i = 12345, layout for 12345 must be known at compile time. ?) This
could be
> > done by just setting some enum std::platform_endianness.
>
> My guess is that a well thought out endianness proposal would sail
> through the committee.
>
> Think about how the standard already specifies such things. It's an
> implementation property. So the target would like be <limits>, and
> C++14.
>
> Perhaps something like:
> constexpr endian endianness() noexcept;
>
> Where endian is an enum class with big, little, and possibly some
> others defined.
>
> Figure out how to handle odd-ball endianness. Maybe allow endian to
> have an additional implementation defined member if the endianness
> isn't big or little.
>
> Write a proposal. The committee is an all volunteer organization. If
> you don't volunteer to write the proposal, it is doubtful anyone else
> will step forward.
>
> In the proposal, don't speculate on how such a function might be
> implemented, other than saying it might require compiler support. Do
> mention the many times similar features have been implemented, usually
> by macros such as in the Boost endian.hpp header.
>
> Send me the proposal. I'll get a number assigned and champion it
> before the committee. Or show up at the next meeting (Bristol, UK, in
> April) and champion it yourself:-)
>
> --Beman
>
> --
>
>
>
Do keep in mind that endianness facilities are already being worked on by
SG4.
--
--e89a8ff1c6c838784704d10dfb1c
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<p><br>
On Dec 17, 2012 5:00 PM, "Beman Dawes" <<a href=3D"mailto:bdaw=
es@acm.org">bdawes@acm.org</a>> wrote:<br>
><br>
> On Mon, Dec 17, 2012 at 12:10 AM, =A0<<a href=3D"mailto:cooky451@gm=
ail.com">cooky451@gmail.com</a>> wrote:<br>
> > Hi,<br>
> ><br>
> > I think this two features could help a lot of programmers out:<br=
>
> ><br>
> > 1. Compile time endianness checking. As far as I know, there'=
s no way to do<br>
> > that right now, even with constexpr. (The usual method is casting=
a<br>
> > uint16_t* to a uint8_t* and checking it's value.) With the C+=
+ approach to<br>
> > do many things at compile time, this information could be extreme=
ly helpful<br>
> > to some low-level algorithms. (e.g. SHA-2) I also think the compi=
ler has<br>
> > this information anyway, since he has to put constant values in m=
emory. (int<br>
> > i =3D 12345, layout for 12345 must be known at compile time. ?) T=
his could be<br>
> > done by just setting some enum std::platform_endianness.<br>
><br>
> My guess is that a well thought out endianness proposal would sail<br>
> through the committee.<br>
><br>
> Think about how the standard already specifies such things. It's a=
n<br>
> implementation property. So the target would like be <limits>, a=
nd<br>
> C++14.<br>
><br>
> Perhaps something like:<br>
> =A0 =A0constexpr endian endianness() noexcept;<br>
><br>
> Where endian is an enum class with big, little, and possibly some<br>
> others defined.<br>
><br>
> Figure out how to handle odd-ball endianness. Maybe allow endian to<br=
>
> have an additional implementation defined member if the endianness<br>
> isn't big or little.<br>
><br>
> Write a proposal. The committee is an all volunteer organization. If<b=
r>
> you don't volunteer to write the proposal, it is doubtful anyone e=
lse<br>
> will step forward.<br>
><br>
> In the proposal, don't speculate on how such a function might be<b=
r>
> implemented, other than saying it might require compiler support. Do<b=
r>
> mention the many times similar features have been implemented, usually=
<br>
> by macros such as in the Boost endian.hpp header.<br>
><br>
> Send me the proposal. I'll get a number assigned and champion it<b=
r>
> before the committee. Or show up at the next meeting (Bristol, UK, in<=
br>
> April) and champion it yourself:-)<br>
><br>
> --Beman<br>
><br>
> --<br>
><br>
><br>
><br>
Do keep in mind that endianness facilities are already being worked on by S=
G4.</p>
<p></p>
-- <br />
<br />
<br />
<br />
--e89a8ff1c6c838784704d10dfb1c--
.
Author: Beman Dawes <bdawes@acm.org>
Date: Mon, 17 Dec 2012 10:53:15 -0500
Raw View
On Mon, Dec 17, 2012 at 10:24 AM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
....
>>
> Do keep in mind that endianness facilities are already being worked on by
> SG4.
Do you have a Doc number for that?
Is their work limited to a networking context? The arithmetic
endianness discussed in this thread would presumably fall under SG6,
Numerics, once LEWG passes any proposal to them.
--Beman
--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Mon, 17 Dec 2012 19:03:43 +0200
Raw View
On 17 December 2012 17:53, Beman Dawes <bdawes@acm.org> wrote:
>> Do keep in mind that endianness facilities are already being worked on by
>> SG4.
> Do you have a Doc number for that?
Not yet, I got the impression that Kyle was about to create such a document
before the end of the year.
> Is their work limited to a networking context? The arithmetic
> endianness discussed in this thread would presumably fall under SG6,
> Numerics, once LEWG passes any proposal to them.
In this case I wouldn't expect to see a minimal only-what-networking-needs
proposal, since networking just needs the equivalent of hton* and ntoh*, but
I suppose querying system endianness (preferably without having to hton a 0x00ff
and checking whether it changed) and performing endianness swaps would
be good tools to have in general. I don't know whether there's
anything more special
in the arithmetic sense.
It seems this would be a good area for close cooperation between LEWG and SG4,
and also SG6 if need be.
--
.