diff options
author | bcook <> | 2014-08-12 15:02:52 +0000 |
---|---|---|
committer | bcook <> | 2014-08-12 15:02:52 +0000 |
commit | 0484ae89e6ed3d0745a7be23512cbae1b3c6e2c8 (patch) | |
tree | 6ff672e8a04986250a3415d25f25baf90920236f | |
parent | 061d595d7859c456aec41e57ebdd900e4087395c (diff) | |
download | openbsd-0484ae89e6ed3d0745a7be23512cbae1b3c6e2c8.tar.gz openbsd-0484ae89e6ed3d0745a7be23512cbae1b3c6e2c8.tar.bz2 openbsd-0484ae89e6ed3d0745a7be23512cbae1b3c6e2c8.zip |
Replace intrinsic ROTATE macros with an inline.
Without the cast/mask, the compiler is allowed to optimize this directly
to the correct CPU intrinsic for rotate.
-rw-r--r-- | src/lib/libcrypto/md32_common.h | 51 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/md32_common.h | 51 |
2 files changed, 20 insertions, 82 deletions
diff --git a/src/lib/libcrypto/md32_common.h b/src/lib/libcrypto/md32_common.h index af753099f5..59de5ee885 100644 --- a/src/lib/libcrypto/md32_common.h +++ b/src/lib/libcrypto/md32_common.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: md32_common.h,v 1.16 2014/07/10 22:45:56 jsing Exp $ */ | 1 | /* $OpenBSD: md32_common.h,v 1.17 2014/08/12 15:02:52 bcook Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -109,6 +109,8 @@ | |||
109 | * <appro@fy.chalmers.se> | 109 | * <appro@fy.chalmers.se> |
110 | */ | 110 | */ |
111 | 111 | ||
112 | #include <stdint.h> | ||
113 | |||
112 | #include <openssl/opensslconf.h> | 114 | #include <openssl/opensslconf.h> |
113 | 115 | ||
114 | #if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN) | 116 | #if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN) |
@@ -140,47 +142,14 @@ | |||
140 | #endif | 142 | #endif |
141 | 143 | ||
142 | /* | 144 | /* |
143 | * Engage compiler specific rotate intrinsic function if available. | 145 | * This common idiom is recognized by the compiler and turned into a |
146 | * CPU-specific intrinsic as appropriate. | ||
147 | * e.g. GCC optimizes to roll on amd64 at -O0 | ||
144 | */ | 148 | */ |
145 | #undef ROTATE | 149 | static inline uint32_t ROTATE(uint32_t a, uint32_t n) |
146 | #if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) | 150 | { |
147 | /* | 151 | return (a<<n)|(a>>(32-n)); |
148 | * Some GNU C inline assembler templates. Note that these are | 152 | } |
149 | * rotates by *constant* number of bits! But that's exactly | ||
150 | * what we need here... | ||
151 | * <appro@fy.chalmers.se> | ||
152 | */ | ||
153 | # if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) | ||
154 | # define ROTATE(a,n) ({ register unsigned int ret; \ | ||
155 | asm ( \ | ||
156 | "roll %1,%0" \ | ||
157 | : "=r"(ret) \ | ||
158 | : "I"(n), "0"((unsigned int)(a)) \ | ||
159 | : "cc"); \ | ||
160 | ret; \ | ||
161 | }) | ||
162 | # elif defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \ | ||
163 | defined(__powerpc) || defined(__ppc__) || defined(__powerpc64__) | ||
164 | # define ROTATE(a,n) ({ register unsigned int ret; \ | ||
165 | asm ( \ | ||
166 | "rlwinm %0,%1,%2,0,31" \ | ||
167 | : "=r"(ret) \ | ||
168 | : "r"(a), "I"(n)); \ | ||
169 | ret; \ | ||
170 | }) | ||
171 | # elif defined(__s390x__) | ||
172 | # define ROTATE(a,n) ({ register unsigned int ret; \ | ||
173 | asm ("rll %0,%1,%2" \ | ||
174 | : "=r"(ret) \ | ||
175 | : "r"(a), "I"(n)); \ | ||
176 | ret; \ | ||
177 | }) | ||
178 | # endif | ||
179 | #endif | ||
180 | |||
181 | #ifndef ROTATE | ||
182 | #define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) | ||
183 | #endif | ||
184 | 153 | ||
185 | #if defined(DATA_ORDER_IS_BIG_ENDIAN) | 154 | #if defined(DATA_ORDER_IS_BIG_ENDIAN) |
186 | 155 | ||
diff --git a/src/lib/libssl/src/crypto/md32_common.h b/src/lib/libssl/src/crypto/md32_common.h index af753099f5..59de5ee885 100644 --- a/src/lib/libssl/src/crypto/md32_common.h +++ b/src/lib/libssl/src/crypto/md32_common.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: md32_common.h,v 1.16 2014/07/10 22:45:56 jsing Exp $ */ | 1 | /* $OpenBSD: md32_common.h,v 1.17 2014/08/12 15:02:52 bcook Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -109,6 +109,8 @@ | |||
109 | * <appro@fy.chalmers.se> | 109 | * <appro@fy.chalmers.se> |
110 | */ | 110 | */ |
111 | 111 | ||
112 | #include <stdint.h> | ||
113 | |||
112 | #include <openssl/opensslconf.h> | 114 | #include <openssl/opensslconf.h> |
113 | 115 | ||
114 | #if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN) | 116 | #if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN) |
@@ -140,47 +142,14 @@ | |||
140 | #endif | 142 | #endif |
141 | 143 | ||
142 | /* | 144 | /* |
143 | * Engage compiler specific rotate intrinsic function if available. | 145 | * This common idiom is recognized by the compiler and turned into a |
146 | * CPU-specific intrinsic as appropriate. | ||
147 | * e.g. GCC optimizes to roll on amd64 at -O0 | ||
144 | */ | 148 | */ |
145 | #undef ROTATE | 149 | static inline uint32_t ROTATE(uint32_t a, uint32_t n) |
146 | #if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) | 150 | { |
147 | /* | 151 | return (a<<n)|(a>>(32-n)); |
148 | * Some GNU C inline assembler templates. Note that these are | 152 | } |
149 | * rotates by *constant* number of bits! But that's exactly | ||
150 | * what we need here... | ||
151 | * <appro@fy.chalmers.se> | ||
152 | */ | ||
153 | # if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) | ||
154 | # define ROTATE(a,n) ({ register unsigned int ret; \ | ||
155 | asm ( \ | ||
156 | "roll %1,%0" \ | ||
157 | : "=r"(ret) \ | ||
158 | : "I"(n), "0"((unsigned int)(a)) \ | ||
159 | : "cc"); \ | ||
160 | ret; \ | ||
161 | }) | ||
162 | # elif defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \ | ||
163 | defined(__powerpc) || defined(__ppc__) || defined(__powerpc64__) | ||
164 | # define ROTATE(a,n) ({ register unsigned int ret; \ | ||
165 | asm ( \ | ||
166 | "rlwinm %0,%1,%2,0,31" \ | ||
167 | : "=r"(ret) \ | ||
168 | : "r"(a), "I"(n)); \ | ||
169 | ret; \ | ||
170 | }) | ||
171 | # elif defined(__s390x__) | ||
172 | # define ROTATE(a,n) ({ register unsigned int ret; \ | ||
173 | asm ("rll %0,%1,%2" \ | ||
174 | : "=r"(ret) \ | ||
175 | : "r"(a), "I"(n)); \ | ||
176 | ret; \ | ||
177 | }) | ||
178 | # endif | ||
179 | #endif | ||
180 | |||
181 | #ifndef ROTATE | ||
182 | #define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) | ||
183 | #endif | ||
184 | 153 | ||
185 | #if defined(DATA_ORDER_IS_BIG_ENDIAN) | 154 | #if defined(DATA_ORDER_IS_BIG_ENDIAN) |
186 | 155 | ||