mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Glenn Weinberg <glenn@cognitive-electronics.com>
To: Rich Felker <dalias@libc.org>
Cc: musl@lists.openwall.com
Subject: Re: Further limits/stdint issues
Date: Wed, 3 Dec 2014 11:34:02 -0500	[thread overview]
Message-ID: <550452A6-49D8-4CED-91E1-5F5A9AE4A33E@cognitive-electronics.com> (raw)
In-Reply-To: <20141203050334.GF4574@brightrain.aerifal.cx>


> On Dec 3, 2014, at 12:03 AM, Rich Felker <dalias@libc.org> wrote:
> 
> On Tue, Dec 02, 2014 at 11:10:58PM -0500, Glenn Weinberg wrote:
>> 
>>> On Dec 2, 2014, at 8:02 PM, Rich Felker <dalias@libc.org> wrote:
>>> 
>>> The fast16/fast32 types and limits are still in bits/stdint.h despite
>>> not varying between archs. Removing those would make bits/stdint.h
>>> tiny/trivial. Aside from PAGE_SIZE, both bits/limits.h and
>>> bits/stdint.h would essentially have no information except
>>> "long/pointer size" and maybe we could even eventually eliminate them
>>> by having a global idea of "wordsize".
>> 
>> I don't think it's safe to make such assumptions. Our architecture
>> is native 64-bit, so we define all the fast types as 64-bit.
> 
> Could you elaborate on your motivations? There's no inherent reason
> that the fast types should be defined as 64-bit just because the
> native word size is 64-bit, and there are lots of reasons against it.

I can, although I need to be a bit circumspect because our product won't be in the market for another year or so and thus we're not exposing all the details yet.

The fundamental answer is that our architecture does not define any 8, 16 or 32-bit integer arithmetic operations.  Integer add, subtract, divide and remainder take 64-bit operands and produce a 64-bit result; integer multiply, multiply-add and multiply-subtract take 64-bit operands and produce a 128-bit result.

> Lots of people misinterpret the "fast" types as "fast unit for moving
> data", i.e. in the sense of "given N bytes of data to move, what's the
> fastest type to move it as?" This is not the meaning the C language
> assigns to them; in fact this sense is rather meaningless since C does
> not permit the aliasing that would be needed to move data as any type
> other than its actual type or a character type.

Don't think I'm one of those people, but I've been wrong before :-)

> Rather, "fast" is a matter of "given N values, possibly with just N=1,
> what type should be used to optimize operations on the value(s)?" In
> this sense, it's almost always best for the fast type to be the same
> as the least type, unless the least type incurs some heavy penalty
> (e.g. a machine that can't do 16-bit loads and stores and has to
> emulate them with byte loads/stores or atomic cas on larger words).

> As an example, take x86_64, where glibc made their [u]int_fast32_t
> types 64-bit. Addition and subtraction are the same speed for 32- or
> 64-bit operations, and perhaps multiplication is too (?), but division
> is significantly slower for 64-bit, and perhaps more importantly,
> using 64-bit storage doubles the number of cache lines you use and
> effectively halves the size of your cache.

While we have 8, 16 and 32-bit loads and stores that promote into/demote from a 64-bit register, there is a penalty for stores of less than 64 bits.

> If you have a good reason that the fast types should be 64-bit on some
> archs, I'd like to hear it. I'm open to listening to alternative views
> on this.

I hope this explains our reasoning sufficiently.  If not, I'd be happy to discuss this further privately.

	Regards,

	Glenn
--
Glenn Weinberg
Vice President, Product
Cognitive Electronics, Inc.
www.cognitive-electronics.com
glenn@cognitive-electronics.com





  reply	other threads:[~2014-12-03 16:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-03  1:02 Rich Felker
2014-12-03  4:10 ` Glenn Weinberg
2014-12-03  5:03   ` Rich Felker
2014-12-03 16:34     ` Glenn Weinberg [this message]
2014-12-03 17:01       ` Rich Felker
2014-12-03 21:08         ` Glenn Weinberg
2014-12-03 10:38 ` Jens Gustedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=550452A6-49D8-4CED-91E1-5F5A9AE4A33E@cognitive-electronics.com \
    --to=glenn@cognitive-electronics.com \
    --cc=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).