Use __emul under msvc x86 for fast 64 = 32 * 32

Update uclouvain/openjpeg#220
This commit is contained in:
mayeut 2015-07-27 20:12:48 +02:00
parent 45ccf501f0
commit b0035538af
2 changed files with 14 additions and 2 deletions

View File

@ -162,12 +162,16 @@ static INLINE long opj_lrintf(float f) {
} }
#endif #endif
#if defined(_MSC_VER) && (_MSC_VER < 1400) #if defined(_MSC_VER) && (_MSC_VER < 1400)
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#endif #endif
/* MSVC x86 is really bad at doing int64 = int32 * int32 on its own. Use intrinsic. */
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
# include <intrin.h>
# pragma intrinsic(__emul)
#endif
#include "opj_inttypes.h" #include "opj_inttypes.h"
#include "opj_clock.h" #include "opj_clock.h"
#include "opj_malloc.h" #include "opj_malloc.h"

View File

@ -184,7 +184,11 @@ Multiply two fixed-precision rational numbers.
@return Returns a * b @return Returns a * b
*/ */
static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) {
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
OPJ_INT64 temp = __emul(a, b);
#else
OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ; OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
#endif
temp += 4096; temp += 4096;
assert((temp >> 13) <= (OPJ_INT64)0x7FFFFFFF); assert((temp >> 13) <= (OPJ_INT64)0x7FFFFFFF);
assert((temp >> 13) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1)); assert((temp >> 13) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1));
@ -192,7 +196,11 @@ static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) {
} }
static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b) {
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
OPJ_INT64 temp = __emul(a, b);
#else
OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ; OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
#endif
temp += 4096; temp += 4096;
assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) <= (OPJ_INT64)0x7FFFFFFF); assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) <= (OPJ_INT64)0x7FFFFFFF);
assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1)); assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1));