* configure.tgt: Fix i?86-*-linux* entry.
* rt/sat_arithmetic.c (__hsail_sat_add_u32, __hsail_sat_add_u64,
__hsail_sat_add_s32, __hsail_sat_add_s64): Use __builtin_add_overflow.
(__hsail_sat_sub_u8, __hsail_sat_sub_u16): Remove pointless for overflow
over maximum.
(__hsail_sat_sub_u32, __hsail_sat_sub_u64, __hsail_sat_sub_s32,
__hsail_sat_sub_s64): Use __builtin_sub_overflow.
(__hsail_sat_mul_u32, __hsail_sat_mul_u64, __hsail_sat_mul_s32,
__hsail_sat_mul_s64): Use __builtin_mul_overflow.
* rt/arithmetic.c (__hsail_borrow_u32, __hsail_borrow_u64): Use
__builtin_sub_overflow_p.
(__hsail_carry_u32, __hsail_carry_u64): Use __builtin_add_overflow_p.
* rt/misc.c (__hsail_groupbaseptr, __hsail_kernargbaseptr_u64):
Cast pointers to uintptr_t first before casting to some other integral
type.
* rt/segment.c (__hsail_segmentp_private, __hsail_segmentp_group): Likewise.
* rt/queue.c (__hsail_ldqueuereadindex, __hsail_ldqueuewriteindex,
__hsail_addqueuewriteindex, __hsail_casqueuewriteindex,
__hsail_stqueuereadindex, __hsail_stqueuewriteindex): Cast integral value
to uintptr_t first before casting to pointer.
* rt/workitems.c (__hsail_alloca_pop_frame): Cast memcpy first argument to
void * to avoid warning.
From-SVN: r245080
+2017-02-01 Jakub Jelinek <jakub@redhat.com>
+
+ * configure.tgt: Fix i?86-*-linux* entry.
+ * rt/sat_arithmetic.c (__hsail_sat_add_u32, __hsail_sat_add_u64,
+ __hsail_sat_add_s32, __hsail_sat_add_s64): Use __builtin_add_overflow.
+ (__hsail_sat_sub_u8, __hsail_sat_sub_u16): Remove pointless for overflow
+ over maximum.
+ (__hsail_sat_sub_u32, __hsail_sat_sub_u64, __hsail_sat_sub_s32,
+ __hsail_sat_sub_s64): Use __builtin_sub_overflow.
+ (__hsail_sat_mul_u32, __hsail_sat_mul_u64, __hsail_sat_mul_s32,
+ __hsail_sat_mul_s64): Use __builtin_mul_overflow.
+ * rt/arithmetic.c (__hsail_borrow_u32, __hsail_borrow_u64): Use
+ __builtin_sub_overflow_p.
+ (__hsail_carry_u32, __hsail_carry_u64): Use __builtin_add_overflow_p.
+ * rt/misc.c (__hsail_groupbaseptr, __hsail_kernargbaseptr_u64):
+ Cast pointers to uintptr_t first before casting to some other integral
+ type.
+ * rt/segment.c (__hsail_segmentp_private, __hsail_segmentp_group): Likewise.
+ * rt/queue.c (__hsail_ldqueuereadindex, __hsail_ldqueuewriteindex,
+ __hsail_addqueuewriteindex, __hsail_casqueuewriteindex,
+ __hsail_stqueuereadindex, __hsail_stqueuewriteindex): Cast integral value
+ to uintptr_t first before casting to pointer.
+ * rt/workitems.c (__hsail_alloca_pop_frame): Cast memcpy first argument to
+ void * to avoid warning.
+
2017-01-27 Pekka Jääskeläinen <pekka.jaaskelainen@parmance.com>
* configure.tgt: Moved the white list of supported targets here
# broken systems. Currently it has been tested only on x86_64 Linux
# of the upstream gcc targets. More targets shall be added after testing.
case "${target}" in
- i[[3456789]]86-*linux*)
- ;;
- x86_64-*-linux*)
+ x86_64-*-linux* | i?86-*-linux*)
;;
*)
UNSUPPORTED=1
uint32_t
__hsail_borrow_u32 (uint32_t a, uint32_t b)
{
- uint64_t c = (uint64_t) a - (uint64_t) b;
- if (c > UINT32_MAX)
- return 1;
- else
- return 0;
+ return __builtin_sub_overflow_p (a, b, a);
}
uint64_t
__hsail_borrow_u64 (uint64_t a, uint64_t b)
{
- __uint128_t c = (__uint128_t) a - (__uint128_t) b;
- if (c > UINT64_MAX)
- return 1;
- else
- return 0;
+ return __builtin_sub_overflow_p (a, b, a);
}
uint32_t
__hsail_carry_u32 (uint32_t a, uint32_t b)
{
- uint64_t c = (uint64_t) a + (uint64_t) b;
- if (c > UINT32_MAX)
- return 1;
- else
- return 0;
+ return __builtin_add_overflow_p (a, b, a);
}
uint64_t
__hsail_carry_u64 (uint64_t a, uint64_t b)
{
- __uint128_t c = (__uint128_t) a + (__uint128_t) b;
- if (c > UINT64_MAX)
- return 1;
- else
- return 0;
+ return __builtin_add_overflow_p (a, b, a);
}
float
uint32_t
__hsail_groupbaseptr (PHSAWorkItem *wi)
{
- return (uint32_t) (uint64_t) (wi->wg->group_base_ptr
- - wi->launch_data->group_segment_start_addr);
+ return (uint32_t) (uintptr_t) (wi->wg->group_base_ptr
+ - wi->launch_data->group_segment_start_addr);
}
uint64_t
{
/* For now assume only a single kernarg allocation at a time.
Proper kernarg memory management to do. */
- return (uint64_t) wi->launch_data->kernarg_addr;
+ return (uint64_t) (uintptr_t) wi->launch_data->kernarg_addr;
}
uint32_t
uint64_t
__hsail_ldqueuereadindex (uint64_t queue_addr)
{
- phsa_queue_t *queue = (phsa_queue_t *) queue_addr;
+ phsa_queue_t *queue = (phsa_queue_t *) (uintptr_t) queue_addr;
return queue->read_index;
}
uint64_t
__hsail_ldqueuewriteindex (uint64_t queue_addr)
{
- phsa_queue_t *queue = (phsa_queue_t *) queue_addr;
+ phsa_queue_t *queue = (phsa_queue_t *) (uintptr_t) queue_addr;
return queue->write_index;
}
uint64_t
__hsail_addqueuewriteindex (uint64_t queue_addr, uint64_t value)
{
- phsa_queue_t *queue = (phsa_queue_t *) queue_addr;
+ phsa_queue_t *queue = (phsa_queue_t *) (uintptr_t) queue_addr;
return __sync_fetch_and_add (&queue->write_index, value);
}
__hsail_casqueuewriteindex (uint64_t queue_addr, uint64_t cmp_value,
uint64_t new_value)
{
- phsa_queue_t *queue = (phsa_queue_t *) queue_addr;
+ phsa_queue_t *queue = (phsa_queue_t *) (uintptr_t) queue_addr;
return __sync_val_compare_and_swap (&queue->write_index, cmp_value,
new_value);
}
void
__hsail_stqueuereadindex (uint64_t queue_addr, uint64_t value)
{
- phsa_queue_t *queue = (phsa_queue_t *) queue_addr;
+ phsa_queue_t *queue = (phsa_queue_t *) (uintptr_t) queue_addr;
queue->read_index = value;
}
void
__hsail_stqueuewriteindex (uint64_t queue_addr, uint64_t value)
{
- phsa_queue_t *queue = (phsa_queue_t *) queue_addr;
+ phsa_queue_t *queue = (phsa_queue_t *) (uintptr_t) queue_addr;
queue->write_index = value;
}
uint32_t
__hsail_sat_add_u32 (uint32_t a, uint32_t b)
{
- uint64_t c = (uint64_t) a + (uint64_t) b;
- if (c > UINT32_MAX)
+ uint32_t c;
+ if (__builtin_add_overflow (a, b, &c))
return UINT32_MAX;
- else
- return c;
+ return c;
}
uint64_t
__hsail_sat_add_u64 (uint64_t a, uint64_t b)
{
- __uint128_t c = (__uint128_t) a + (__uint128_t) b;
- if (c > UINT64_MAX)
+ uint64_t c;
+ if (__builtin_add_overflow (a, b, &c))
return UINT64_MAX;
- else
- return c;
+ return c;
}
int8_t
int32_t
__hsail_sat_add_s32 (int32_t a, int32_t b)
{
- int64_t c = (int64_t) a + (int64_t) b;
- if (c > INT32_MAX)
- return INT32_MAX;
- else if (c < INT32_MIN)
- return INT32_MIN;
- else
- return c;
+ int32_t c;
+ if (__builtin_add_overflow (a, b, &c))
+ return b < 0 ? INT32_MIN : INT32_MAX;
+ return c;
}
int64_t
__hsail_sat_add_s64 (int64_t a, int64_t b)
{
- __int128_t c = (__int128_t) a + (__int128_t) b;
- if (c > INT64_MAX)
- return INT64_MAX;
- else if (c < INT64_MIN)
- return INT64_MIN;
- else
- return c;
+ int64_t c;
+ if (__builtin_add_overflow (a, b, &c))
+ return b < 0 ? INT64_MIN : INT64_MAX;
+ return c;
}
uint8_t
int16_t c = (uint16_t) a - (uint16_t) b;
if (c < 0)
return 0;
- else if (c > UINT8_MAX)
- return UINT8_MAX;
else
return c;
}
int32_t c = (uint32_t) a - (uint32_t) b;
if (c < 0)
return 0;
- else if (c > UINT16_MAX)
- return UINT16_MAX;
else
return c;
}
uint32_t
__hsail_sat_sub_u32 (uint32_t a, uint32_t b)
{
- int64_t c = (uint64_t) a - (uint64_t) b;
- if (c < 0)
+ uint32_t c;
+ if (__builtin_sub_overflow (a, b, &c))
return 0;
- else if (c > UINT32_MAX)
- return UINT32_MAX;
- else
- return c;
+ return c;
}
uint64_t
__hsail_sat_sub_u64 (uint64_t a, uint64_t b)
{
- __int128_t c = (__uint128_t) a - (__uint128_t) b;
- if (c < 0)
+ uint64_t c;
+ if (__builtin_sub_overflow (a, b, &c))
return 0;
- else if (c > UINT64_MAX)
- return UINT64_MAX;
- else
- return c;
+ return c;
}
int8_t
int32_t
__hsail_sat_sub_s32 (int32_t a, int32_t b)
{
- int64_t c = (int64_t) a - (int64_t) b;
- if (c > INT32_MAX)
- return INT32_MAX;
- else if (c < INT32_MIN)
- return INT32_MIN;
- else
- return c;
+ int32_t c;
+ if (__builtin_sub_overflow (a, b, &c))
+ return b < 0 ? INT32_MAX : INT32_MIN;
+ return c;
}
int64_t
__hsail_sat_sub_s64 (int64_t a, int64_t b)
{
- __int128_t c = (__int128_t) a - (__int128_t) b;
- if (c > INT64_MAX)
- return INT64_MAX;
- else if (c < INT64_MIN)
- return INT64_MIN;
- else
- return c;
+ int64_t c;
+ if (__builtin_sub_overflow (a, b, &c))
+ return b < 0 ? INT64_MAX : INT64_MIN;
+ return c;
}
uint8_t
uint32_t
__hsail_sat_mul_u32 (uint32_t a, uint32_t b)
{
- uint64_t c = (uint64_t) a * (uint64_t) b;
- if (c > UINT32_MAX)
+ uint32_t c;
+ if (__builtin_mul_overflow (a, b, &c))
return UINT32_MAX;
- else
- return c;
+ return c;
}
uint64_t
__hsail_sat_mul_u64 (uint64_t a, uint64_t b)
{
- __uint128_t c = (__uint128_t) a * (__uint128_t) b;
- if (c > UINT64_MAX)
+ uint64_t c;
+ if (__builtin_mul_overflow (a, b, &c))
return UINT64_MAX;
- else
- return c;
+ return c;
}
int8_t
int32_t
__hsail_sat_mul_s32 (int32_t a, int32_t b)
{
- int64_t c = (int64_t) a * (int64_t) b;
- if (c > INT32_MAX)
- return INT32_MAX;
- else if (c < INT32_MIN)
- return INT32_MIN;
- else
- return c;
+ int32_t c;
+ if (__builtin_mul_overflow (a, b, &c))
+ return ((a > 0) ^ (b > 0)) ? INT32_MIN : INT32_MAX;
+ return c;
}
int64_t
__hsail_sat_mul_s64 (int64_t a, int64_t b)
{
- __int128_t c = (__int128_t) a * (__int128_t) b;
- if (c > INT64_MAX)
- return INT64_MAX;
- else if (c < INT64_MIN)
- return INT64_MIN;
- else
- return c;
+ int64_t c;
+ if (__builtin_mul_overflow (a, b, &c))
+ return ((a > 0) ^ (b > 0)) ? INT64_MIN : INT64_MAX;
+ return c;
}
if (flat_addr == 0)
return 1;
else
- return (void *) flat_addr >= wi->wg->private_base_ptr
- && (void *) flat_addr
- < wi->wg->private_base_ptr + wi->wg->private_segment_total_size;
+ return ((void *) (uintptr_t) flat_addr >= wi->wg->private_base_ptr
+ && ((void *) (uintptr_t) flat_addr
+ < (wi->wg->private_base_ptr
+ + wi->wg->private_segment_total_size)));
}
uint32_t
if (flat_addr == 0)
return 1;
else
- return (void *) flat_addr >= wi->wg->group_base_ptr
- && (void *) flat_addr < wi->wg->group_base_ptr
- + wi->launch_data->dp->group_segment_size;
+ return ((void *) (uintptr_t) flat_addr >= wi->wg->group_base_ptr
+ && ((void *) (uintptr_t) flat_addr
+ < (wi->wg->group_base_ptr
+ + wi->launch_data->dp->group_segment_size)));
}
uint32_t
volatile PHSAWorkGroup *wg = wi->wg;
wg->alloca_stack_p = wg->alloca_frame_p;
- memcpy (&wg->alloca_frame_p,
+ memcpy ((void *) &wg->alloca_frame_p,
(const void *) (wg->private_base_ptr + wg->alloca_frame_p), 4);
/* Now frame_p points to the beginning of the previous function's
frame and stack_p to its end. */