1 /* multimedia.c -- Builtins for HSAIL multimedia instructions.
3 Copyright (C) 2015-2018 Free Software Foundation, Inc.
4 Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
5 for General Processor Tech.
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files
9 (the "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
31 __hsail_bitalign (uint64_t lower
, uint64_t upper
, uint32_t shift_amount
)
33 shift_amount
= shift_amount
& 31;
34 uint64_t packed_value
= (upper
<< 32) | lower
;
35 return (packed_value
>> shift_amount
) & 0xFFFFFFFF;
39 __hsail_bytealign (uint64_t lower
, uint64_t upper
, uint32_t shift_amount
)
41 shift_amount
= (shift_amount
& 3) * 8;
42 uint64_t packed_value
= (upper
<< 32) | lower
;
43 return (packed_value
>> shift_amount
) & 0xFFFFFFFF;
47 __hsail_lerp (uint32_t a
, uint32_t b
, uint32_t c
)
50 = (((((a
>> 24) & 0xff) + ((b
>> 24) & 0xff) + ((c
>> 24) & 0x1)) / 2)
54 = (((((a
>> 16) & 0xff) + ((b
>> 16) & 0xff) + ((c
>> 16) & 0x1)) / 2)
58 = (((((a
>> 8) & 0xff) + ((b
>> 8) & 0xff) + ((c
>> 8) & 0x1)) / 2) & 0xff)
60 uint32_t e0
= (((a
& 0xff) + (b
& 0xff) + (c
& 0x1)) / 2) & 0xff;
62 return e3
| e2
| e1
| e0
;
66 cvt_neari_sat_u8_f32 (float a
)
70 if (signbit (a
)) return 0;
73 else if (isnan (a
)) return 0;
83 __hsail_packcvt (float a
, float b
, float c
, float d
)
85 return (uint32_t) cvt_neari_sat_u8_f32 (a
)
86 | (uint32_t) cvt_neari_sat_u8_f32 (b
) << 8
87 | (uint32_t) cvt_neari_sat_u8_f32 (c
) << 16
88 | (uint32_t) cvt_neari_sat_u8_f32 (d
) << 24;
92 __hsail_unpackcvt (uint32_t val
, uint32_t index
)
94 return (float) ((val
>> (index
* 8)) & 0xff);
98 abs_diff (uint32_t a
, uint32_t b
)
107 __hsail_sad_u8x4 (uint32_t a
, uint32_t b
, uint32_t add
)
109 return abs_diff ((a
>> 24) & 0xff, (b
>> 24) & 0xff)
110 + abs_diff ((a
>> 16) & 0xff, (b
>> 16) & 0xff)
111 + abs_diff ((a
>> 8) & 0xff, (b
>> 8) & 0xff)
112 + abs_diff ((a
>> 0) & 0xff, (b
>> 0) & 0xff) + add
;
116 __hsail_sad_u16x2 (uint32_t a
, uint32_t b
, uint32_t add
)
118 return abs_diff ((a
>> 16) & 0xffff, (b
>> 16) & 0xffff)
119 + abs_diff ((a
>> 0) & 0xffff, (b
>> 0) & 0xffff) + add
;
123 __hsail_sad_u32 (uint32_t a
, uint32_t b
, uint32_t add
)
125 return abs_diff (a
, b
) + add
;
129 __hsail_sadhi_u16x2_u8x4 (uint32_t a
, uint32_t b
, uint32_t add
)
131 return (abs_diff ((a
>> 24) & 0xff, (b
>> 24) & 0xff) << 16)
132 + (abs_diff ((a
>> 16) & 0xff, (b
>> 16) & 0xff) << 16)
133 + (abs_diff ((a
>> 8) & 0xff, (b
>> 8) & 0xff) << 16)
134 + (abs_diff ((a
>> 0) & 0xff, (b
>> 0) & 0xff) << 16) + add
;