Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230525094209.g45xtqivs2rkskjo@gen2.localdomain>
Date: Thu, 25 May 2023 15:42:09 +0600
From: NRK <nrk@...root.org>
To: musl@...ts.openwall.com
Subject: Re: [C23 new stdlib 2/4] C23: add the memalignment function

On Thu, May 25, 2023 at 11:16:53AM +0200, Jā‚‘ā‚™ā‚› Gustedt wrote:
> I think the intent of those is really to provide instruction level
> support of these bit functionalities that avoids going through
> function calls.

That doesn't really have to be done at the libc level, though. If the
interface is standardized, then compilers can assume their behavior and
substitute in suitable instruction if it feels like it.

For example, both gcc and clang are capable of turning the following
into a single mov instruction on amd64:

	void f(void *p, long n) { memcpy(p, &n, sizeof n); }

Compile with `gcc -O2 -S test.c` and inspect the asm (I've removed some
noise from the output):

	f:
		movq	%rsi, (%rdi)
		ret

As such, I don't think it's necessary to implement these in the headers.
Compilers that already support `__builtin_*` bit functions can be tuned
to understand the C23 bit functions as well.

- NRK

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.