[Mesa-dev] [PATCH 12/24] i965: Initialize registers' file to BAD_FILE.
Matt Turner
mattst88 at gmail.com
Wed Nov 11 15:12:11 PST 2015
On Wed, Nov 11, 2015 at 3:05 PM, Kenneth Graunke <kenneth at whitecape.org> wrote:
> On Wednesday, November 11, 2015 01:07:24 PM Matt Turner wrote:
>> On Wed, Nov 11, 2015 at 12:46 PM, Kenneth Graunke <kenneth at whitecape.org> wrote:
>> > On Monday, November 02, 2015 04:29:22 PM Matt Turner wrote:
>> >> The test (file == BAD_FILE) works on registers for which the constructor
>> >> has not run because BAD_FILE is zero. The next commit will move
>> >> BAD_FILE in the enum so that it's no longer zero.
>> >> ---
>> >> src/mesa/drivers/dri/i965/brw_fs_nir.cpp | 10 +++++++++-
>> >> src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 3 +++
>> >> src/mesa/drivers/dri/i965/brw_vec4_nir.cpp | 9 +++++++++
>> >> 3 files changed, 21 insertions(+), 1 deletion(-)
>> >>
>> >> diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
>> >> index 7eeff93..611347c 100644
>> >> --- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
>> >> +++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
>> >> @@ -260,6 +260,10 @@ void
>> >> fs_visitor::nir_emit_system_values()
>> >> {
>> >> nir_system_values = ralloc_array(mem_ctx, fs_reg, SYSTEM_VALUE_MAX);
>> >> + for (unsigned i = 0; i < SYSTEM_VALUE_MAX; i++) {
>> >> + nir_system_values[i].file = BAD_FILE;
>> >
>> > How about we do this instead:
>> >
>> > nir_system_values[i] = fs_reg();
>> >
>> > That way, they're properly constructed using the default constructor,
>> > which would not only set BAD_FILE, but properly initialize everything,
>> > so we don't have to revisit this if we make other changes in fs_reg().
>>
>> Is it worth is? The function this code exists in is the thing that
>> initializes the system values. And, of course if file == BAD_FILE, no
>> other fields mean anything. Neither of those are likely to change.
>
> Yes. It's the correct thing to do. We don't want partially
> initialized objects. That way lies madness.
Fine. But I think that calloc()ing storage, memsetting it to zero, and
then memsetting it to zero again before initializing it is madness.
More information about the mesa-dev
mailing list