diff mbox

Add GCC's byteswap intrinsics

Message ID 1355406304.19560.39.camel@shinybook.infradead.org (mailing list archive)
State Rejected, archived
Headers show

Commit Message

David Woodhouse Dec. 13, 2012, 1:45 p.m. UTC
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
---
I'm about to make the kernel use these:
 http://git.infradead.org/users/dwmw2/byteswap.git

 lib.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Josh Triplett Dec. 13, 2012, 4:11 p.m. UTC | #1
On Thu, Dec 13, 2012 at 01:45:04PM +0000, David Woodhouse wrote:
> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
> ---
> I'm about to make the kernel use these:
>  http://git.infradead.org/users/dwmw2/byteswap.git
> 
>  lib.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/lib.c b/lib.c
> index 396e9f1..d747a3e 100644
> --- a/lib.c
> +++ b/lib.c
> @@ -698,6 +698,11 @@ void declare_builtin_functions(void)
>  	add_pre_buffer("extern int __builtin_popcountl(unsigned long);\n");
>  	add_pre_buffer("extern int __builtin_popcountll(unsigned long long);\n");
>  
> +	/* And byte-swapping operations.. */
> +	add_pre_buffer("extern short __builtin_bswap16(short);\n");
> +	add_pre_buffer("extern int __builtin_bswap32(int);\n");
> +	add_pre_buffer("extern long long __builtin_bswap64(long long);\n");

GCC defines these to use int16_t, int32_t, and int64_t, respectively.
The first two of those should match up to "short" and "int" without any
issue, but on 64-bit platforms, stdint.h defines int64_t as "long", not
"long long".  That could lead to some type incompatibilities.

- Josh Triplett
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Woodhouse Dec. 13, 2012, 4:29 p.m. UTC | #2
On Thu, 2012-12-13 at 08:11 -0800, Josh Triplett wrote:
> 
> GCC defines these to use int16_t, int32_t, and int64_t, respectively.
> The first two of those should match up to "short" and "int" without any
> issue, but on 64-bit platforms, stdint.h defines int64_t as "long", not
> "long long".  That could lead to some type incompatibilities.

Are we allowed to use int64_t? Or must we pretend that it's still the
20th century and stdint.h might not be present?
diff mbox

Patch

diff --git a/lib.c b/lib.c
index 396e9f1..d747a3e 100644
--- a/lib.c
+++ b/lib.c
@@ -698,6 +698,11 @@  void declare_builtin_functions(void)
 	add_pre_buffer("extern int __builtin_popcountl(unsigned long);\n");
 	add_pre_buffer("extern int __builtin_popcountll(unsigned long long);\n");
 
+	/* And byte-swapping operations.. */
+	add_pre_buffer("extern short __builtin_bswap16(short);\n");
+	add_pre_buffer("extern int __builtin_bswap32(int);\n");
+	add_pre_buffer("extern long long __builtin_bswap64(long long);\n");
+
 	/* And some random ones.. */
 	add_pre_buffer("extern void *__builtin_return_address(unsigned int);\n");
 	add_pre_buffer("extern void *__builtin_extract_return_addr(void *);\n");