diff mbox

[FFmpeg-devel,1/2] avcodec/huffyuvdsp: use an actual unsigned long constant

Message ID 20170208161357.7296-1-jamrial@gmail.com
State Accepted
Commit 21d25da18025856bb30d80173174bb4218a91f82
Headers show

Commit Message

James Almer Feb. 8, 2017, 4:13 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
Decent compilers are smart enough to truncate those ULL constants on targets
where long is 32 bits (and do things like shift+and/add instead of mul).
This is for those that are not.

 libavcodec/huffyuvdsp.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer Feb. 9, 2017, 5:37 p.m. UTC | #1
On Wed, Feb 08, 2017 at 01:13:56PM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> Decent compilers are smart enough to truncate those ULL constants on targets
> where long is 32 bits (and do things like shift+and/add instead of mul).
> This is for those that are not.
> 
>  libavcodec/huffyuvdsp.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

LGTM

thx

[...]
James Almer Feb. 19, 2017, 3:28 p.m. UTC | #2
On 2/9/2017 2:37 PM, Michael Niedermayer wrote:
> On Wed, Feb 08, 2017 at 01:13:56PM -0300, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> Decent compilers are smart enough to truncate those ULL constants on targets
>> where long is 32 bits (and do things like shift+and/add instead of mul).
>> This is for those that are not.
>>
>>  libavcodec/huffyuvdsp.c | 7 +++++--
>>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> LGTM
> 
> thx

Pushed.
diff mbox

Patch

diff --git a/libavcodec/huffyuvdsp.c b/libavcodec/huffyuvdsp.c
index 759ffda0b8..e770923bb2 100644
--- a/libavcodec/huffyuvdsp.c
+++ b/libavcodec/huffyuvdsp.c
@@ -23,10 +23,13 @@ 
 #include "mathops.h"
 #include "huffyuvdsp.h"
 
+// 0x00010001 or 0x0001000100010001 or whatever, depending on the cpu's native arithmetic size
+#define pw_1 (ULONG_MAX / UINT16_MAX)
+
 static void add_int16_c(uint16_t *dst, const uint16_t *src, unsigned mask, int w){
     long i;
-    unsigned long pw_lsb = (mask >> 1) * 0x0001000100010001ULL;
-    unsigned long pw_msb = pw_lsb +  0x0001000100010001ULL;
+    unsigned long pw_lsb = (mask >> 1) * pw_1;
+    unsigned long pw_msb = pw_lsb +  pw_1;
     for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) {
         long a = *(long*)(src+i);
         long b = *(long*)(dst+i);