i965/fs: Replace ud_reg_to_w() with a more general helper function.

Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
Francisco Jerez 2015-02-04 17:58:49 +02:00
parent 63d6d09a3b
commit 509f58740c
2 changed files with 25 additions and 24 deletions

View file

@ -1399,27 +1399,6 @@ fs_generator::generate_set_sample_id(fs_inst *inst,
brw_pop_insn_state(p);
}
/**
* Change the register's data type from UD to W, doubling the strides in order
* to compensate for halving the data type width.
*/
static struct brw_reg
ud_reg_to_w(struct brw_reg r)
{
assert(r.type == BRW_REGISTER_TYPE_UD);
r.type = BRW_REGISTER_TYPE_W;
/* The BRW_*_STRIDE enums are defined so that incrementing the field
* doubles the real stride.
*/
if (r.hstride != 0)
++r.hstride;
if (r.vstride != 0)
++r.vstride;
return r;
}
void
fs_generator::generate_pack_half_2x16_split(fs_inst *inst,
struct brw_reg dst,
@ -1440,9 +1419,9 @@ fs_generator::generate_pack_half_2x16_split(fs_inst *inst,
* (HorzStride) of 2. The 16-bit result is stored in the lower word of
* each destination channel and the upper word is not modified.
*/
struct brw_reg dst_w = ud_reg_to_w(dst);
struct brw_reg dst_w = spread(retype(dst, BRW_REGISTER_TYPE_W), 2);
/* Give each 32-bit channel of dst the form below , where "." means
/* Give each 32-bit channel of dst the form below, where "." means
* unchanged.
* 0x....hhhh
*/
@ -1474,7 +1453,7 @@ fs_generator::generate_unpack_half_2x16_split(fs_inst *inst,
* the source data type must be Word (W). The destination type must be
* F (Float).
*/
struct brw_reg src_w = ud_reg_to_w(src);
struct brw_reg src_w = spread(retype(src, BRW_REGISTER_TYPE_W), 2);
/* Each channel of src has the form of unpackHalf2x16's input: 0xhhhhllll.
* For the Y case, we wish to access only the upper word; therefore

View file

@ -45,6 +45,7 @@
#include <stdbool.h>
#include "main/imports.h"
#include "main/compiler.h"
#include "main/macros.h"
#include "program/prog_instruction.h"
#include "brw_defines.h"
@ -720,6 +721,27 @@ stride(struct brw_reg reg, unsigned vstride, unsigned width, unsigned hstride)
return reg;
}
/**
* Multiply the vertical and horizontal stride of a register by the given
* factor \a s.
*/
static inline struct brw_reg
spread(struct brw_reg reg, unsigned s)
{
if (s) {
assert(is_power_of_two(s));
if (reg.hstride)
reg.hstride += cvt(s) - 1;
if (reg.vstride)
reg.vstride += cvt(s) - 1;
return reg;
} else {
return stride(reg, 0, 1, 0);
}
}
static inline struct brw_reg
vec16(struct brw_reg reg)