Commit 60d2fc23 authored by Nicolai Hähnle's avatar Nicolai Hähnle

gallium/radeon: clean left-shift undefined behavior

Shifting into the sign bit of a signed int is undefined behavior.
Unfortunately, there are potentially many places where this happens using
the register macros.

This commit is the result of running

sed -ie "s/(((\(\w\+\)) & 0x\(\w\+\)) << \(\w\+\))/(((unsigned)(\1) \& 0x\2) << \3)/g"

on all header files in gallium/{r600,radeon,radeonsi}.
Reviewed-by: default avatarMarek Olšák <marek.olsak@amd.com>
parent 62b7958c
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -2,18 +2,18 @@
#ifndef R600_OPCODES_H
#define R600_OPCODES_H
#define R600_S_SQ_CF_WORD1_CF_INST(x) (((x) & 0x7F) << 23)
#define R600_S_SQ_CF_WORD1_CF_INST(x) (((unsigned)(x) & 0x7F) << 23)
#define R600_G_SQ_CF_WORD1_CF_INST(x) (((x) >> 23) & 0x7F)
#define R600_S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(x) (((x) & 0x7F) << 23)
#define R600_S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(x) (((unsigned)(x) & 0x7F) << 23)
#define R600_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(x) (((x) >> 23) & 0x7F)
#define R600_S_SQ_CF_ALU_WORD1_CF_INST(x) (((x) & 0xF) << 26)
#define R600_S_SQ_CF_ALU_WORD1_CF_INST(x) (((unsigned)(x) & 0xF) << 26)
#define R600_G_SQ_CF_ALU_WORD1_CF_INST(x) (((x) >> 26) & 0xF)
#define EG_S_SQ_CF_WORD1_CF_INST(x) (((x) & 0xFF) << 22)
#define EG_S_SQ_CF_WORD1_CF_INST(x) (((unsigned)(x) & 0xFF) << 22)
#define EG_G_SQ_CF_WORD1_CF_INST(x) (((x) >> 22) & 0xFF)
#define EG_S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(x) (((x) & 0xFF) << 22)
#define EG_S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(x) (((unsigned)(x) & 0xFF) << 22)
#define EG_G_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(x) (((x) >> 22) & 0xFF)
#define EG_S_SQ_CF_ALU_WORD1_CF_INST(x) (((x) & 0xF) << 26)
#define EG_S_SQ_CF_ALU_WORD1_CF_INST(x) (((unsigned)(x) & 0xF) << 26)
#define EG_G_SQ_CF_ALU_WORD1_CF_INST(x) (((x) >> 26) & 0xF)
#define V_SQ_CF_WORD1_SQ_CF_INST_NOP R600_S_SQ_CF_WORD1_CF_INST(0x00000000)
......
......@@ -762,9 +762,9 @@ struct pipe_video_buffer *r600_video_buffer_create(struct pipe_context *pipe,
#define R600_LOOP_CONST_OFFSET 0X0003E200
#define EG_LOOP_CONST_OFFSET 0x0003A200
#define PKT_TYPE_S(x) (((x) & 0x3) << 30)
#define PKT_COUNT_S(x) (((x) & 0x3FFF) << 16)
#define PKT3_IT_OPCODE_S(x) (((x) & 0xFF) << 8)
#define PKT_TYPE_S(x) (((unsigned)(x) & 0x3) << 30)
#define PKT_COUNT_S(x) (((unsigned)(x) & 0x3FFF) << 16)
#define PKT3_IT_OPCODE_S(x) (((unsigned)(x) & 0xFF) << 8)
#define PKT3_PREDICATE(x) (((x) >> 0) & 0x1)
#define PKT3(op, count, predicate) (PKT_TYPE_S(3) | PKT_COUNT_S(count) | PKT3_IT_OPCODE_S(op) | PKT3_PREDICATE(predicate))
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -762,9 +762,9 @@ r600_get_sampler_view_priority(struct r600_resource *res)
/* For MSAA sample positions. */
#define FILL_SREG(s0x, s0y, s1x, s1y, s2x, s2y, s3x, s3y) \
(((s0x) & 0xf) | (((s0y) & 0xf) << 4) | \
(((s1x) & 0xf) << 8) | (((s1y) & 0xf) << 12) | \
(((s2x) & 0xf) << 16) | (((s2y) & 0xf) << 20) | \
(((s3x) & 0xf) << 24) | (((s3y) & 0xf) << 28))
(((s0x) & 0xf) | (((unsigned)(s0y) & 0xf) << 4) | \
(((unsigned)(s1x) & 0xf) << 8) | (((unsigned)(s1y) & 0xf) << 12) | \
(((unsigned)(s2x) & 0xf) << 16) | (((unsigned)(s2y) & 0xf) << 20) | \
(((unsigned)(s3x) & 0xf) << 24) | (((unsigned)(s3y) & 0xf) << 28))
#endif
This diff is collapsed.
......@@ -38,13 +38,13 @@
#include "vl/vl_video_buffer.h"
/* UVD uses PM4 packet type 0 and 2 */
#define RUVD_PKT_TYPE_S(x) (((x) & 0x3) << 30)
#define RUVD_PKT_TYPE_S(x) (((unsigned)(x) & 0x3) << 30)
#define RUVD_PKT_TYPE_G(x) (((x) >> 30) & 0x3)
#define RUVD_PKT_TYPE_C 0x3FFFFFFF
#define RUVD_PKT_COUNT_S(x) (((x) & 0x3FFF) << 16)
#define RUVD_PKT_COUNT_S(x) (((unsigned)(x) & 0x3FFF) << 16)
#define RUVD_PKT_COUNT_G(x) (((x) >> 16) & 0x3FFF)
#define RUVD_PKT_COUNT_C 0xC000FFFF
#define RUVD_PKT0_BASE_INDEX_S(x) (((x) & 0xFFFF) << 0)
#define RUVD_PKT0_BASE_INDEX_S(x) (((unsigned)(x) & 0xFFFF) << 0)
#define RUVD_PKT0_BASE_INDEX_G(x) (((x) >> 0) & 0xFFFF)
#define RUVD_PKT0_BASE_INDEX_C 0xFFFF0000
#define RUVD_PKT0(index, count) (RUVD_PKT_TYPE_S(0) | RUVD_PKT0_BASE_INDEX_S(index) | RUVD_PKT_COUNT_S(count))
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment