Merge commit 'origin/gallium-master-merge'
[mesa.git] / src / gallium / drivers / i965simple / brw_eu.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS 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 COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32
33 #include "brw_context.h"
34 #include "brw_defines.h"
35 #include "brw_eu.h"
36
37
38
39 /* How does predicate control work when execution_size != 8? Do I
40 * need to test/set for 0xffff when execution_size is 16?
41 */
42 void brw_set_predicate_control_flag_value( struct brw_compile *p, unsigned value )
43 {
44 p->current->header.predicate_control = BRW_PREDICATE_NONE;
45
46 if (value != 0xff) {
47 if (value != p->flag_value) {
48 brw_push_insn_state(p);
49 brw_MOV(p, brw_flag_reg(), brw_imm_uw(value));
50 p->flag_value = value;
51 brw_pop_insn_state(p);
52 }
53
54 p->current->header.predicate_control = BRW_PREDICATE_NORMAL;
55 }
56 }
57
58 void brw_set_predicate_control( struct brw_compile *p, unsigned pc )
59 {
60 p->current->header.predicate_control = pc;
61 }
62
63 void brw_set_conditionalmod( struct brw_compile *p, unsigned conditional )
64 {
65 p->current->header.destreg__conditonalmod = conditional;
66 }
67
68 void brw_set_access_mode( struct brw_compile *p, unsigned access_mode )
69 {
70 p->current->header.access_mode = access_mode;
71 }
72
73 void brw_set_compression_control( struct brw_compile *p, boolean compression_control )
74 {
75 p->current->header.compression_control = compression_control;
76 }
77
78 void brw_set_mask_control( struct brw_compile *p, unsigned value )
79 {
80 p->current->header.mask_control = value;
81 }
82
83 void brw_set_saturate( struct brw_compile *p, unsigned value )
84 {
85 p->current->header.saturate = value;
86 }
87
88 void brw_push_insn_state( struct brw_compile *p )
89 {
90 assert(p->current != &p->stack[BRW_EU_MAX_INSN_STACK-1]);
91 memcpy(p->current+1, p->current, sizeof(struct brw_instruction));
92 p->current++;
93 }
94
95 void brw_pop_insn_state( struct brw_compile *p )
96 {
97 assert(p->current != p->stack);
98 p->current--;
99 }
100
101
102 /***********************************************************************
103 */
104 void brw_init_compile( struct brw_compile *p )
105 {
106 p->nr_insn = 0;
107 p->current = p->stack;
108 memset(p->current, 0, sizeof(p->current[0]));
109
110 /* Some defaults?
111 */
112 brw_set_mask_control(p, BRW_MASK_ENABLE); /* what does this do? */
113 brw_set_saturate(p, 0);
114 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
115 brw_set_predicate_control_flag_value(p, 0xff);
116 }
117
118
119 const unsigned *brw_get_program( struct brw_compile *p,
120 unsigned *sz )
121 {
122 unsigned i;
123
124 for (i = 0; i < 8; i++)
125 brw_NOP(p);
126
127 *sz = p->nr_insn * sizeof(struct brw_instruction);
128 return (const unsigned *)p->store;
129 }
130