mesa: Remove Mesa IR opcodes that existed only for NV_vertex_program.
[mesa.git] / src / mesa / program / prog_execute.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.3
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file prog_execute.c
27 * Software interpreter for vertex/fragment programs.
28 * \author Brian Paul
29 */
30
31 /*
32 * NOTE: we do everything in single-precision floating point; we don't
33 * currently observe the single/half/fixed-precision qualifiers.
34 *
35 */
36
37
38 #include "main/glheader.h"
39 #include "main/colormac.h"
40 #include "main/macros.h"
41 #include "prog_execute.h"
42 #include "prog_instruction.h"
43 #include "prog_parameter.h"
44 #include "prog_print.h"
45 #include "prog_noise.h"
46
47
48 /* debug predicate */
49 #define DEBUG_PROG 0
50
51
52 /**
53 * Set x to positive or negative infinity.
54 */
55 #if defined(USE_IEEE) || defined(_WIN32)
56 #define SET_POS_INFINITY(x) \
57 do { \
58 fi_type fi; \
59 fi.i = 0x7F800000; \
60 x = fi.f; \
61 } while (0)
62 #define SET_NEG_INFINITY(x) \
63 do { \
64 fi_type fi; \
65 fi.i = 0xFF800000; \
66 x = fi.f; \
67 } while (0)
68 #elif defined(VMS)
69 #define SET_POS_INFINITY(x) x = __MAXFLOAT
70 #define SET_NEG_INFINITY(x) x = -__MAXFLOAT
71 #else
72 #define SET_POS_INFINITY(x) x = (GLfloat) HUGE_VAL
73 #define SET_NEG_INFINITY(x) x = (GLfloat) -HUGE_VAL
74 #endif
75
76 #define SET_FLOAT_BITS(x, bits) ((fi_type *) (void *) &(x))->i = bits
77
78
79 static const GLfloat ZeroVec[4] = { 0.0F, 0.0F, 0.0F, 0.0F };
80
81
82 /**
83 * Return a pointer to the 4-element float vector specified by the given
84 * source register.
85 */
86 static inline const GLfloat *
87 get_src_register_pointer(const struct prog_src_register *source,
88 const struct gl_program_machine *machine)
89 {
90 const struct gl_program *prog = machine->CurProgram;
91 GLint reg = source->Index;
92
93 if (source->RelAddr) {
94 /* add address register value to src index/offset */
95 reg += machine->AddressReg[0][0];
96 if (reg < 0) {
97 return ZeroVec;
98 }
99 }
100
101 switch (source->File) {
102 case PROGRAM_TEMPORARY:
103 if (reg >= MAX_PROGRAM_TEMPS)
104 return ZeroVec;
105 return machine->Temporaries[reg];
106
107 case PROGRAM_INPUT:
108 if (prog->Target == GL_VERTEX_PROGRAM_ARB) {
109 if (reg >= VERT_ATTRIB_MAX)
110 return ZeroVec;
111 return machine->VertAttribs[reg];
112 }
113 else {
114 if (reg >= FRAG_ATTRIB_MAX)
115 return ZeroVec;
116 return machine->Attribs[reg][machine->CurElement];
117 }
118
119 case PROGRAM_OUTPUT:
120 if (reg >= MAX_PROGRAM_OUTPUTS)
121 return ZeroVec;
122 return machine->Outputs[reg];
123
124 case PROGRAM_LOCAL_PARAM:
125 if (reg >= MAX_PROGRAM_LOCAL_PARAMS)
126 return ZeroVec;
127 return machine->CurProgram->LocalParams[reg];
128
129 case PROGRAM_ENV_PARAM:
130 if (reg >= MAX_PROGRAM_ENV_PARAMS)
131 return ZeroVec;
132 return machine->EnvParams[reg];
133
134 case PROGRAM_STATE_VAR:
135 /* Fallthrough */
136 case PROGRAM_CONSTANT:
137 /* Fallthrough */
138 case PROGRAM_UNIFORM:
139 /* Fallthrough */
140 case PROGRAM_NAMED_PARAM:
141 if (reg >= (GLint) prog->Parameters->NumParameters)
142 return ZeroVec;
143 return (GLfloat *) prog->Parameters->ParameterValues[reg];
144
145 case PROGRAM_SYSTEM_VALUE:
146 assert(reg < Elements(machine->SystemValues));
147 return machine->SystemValues[reg];
148
149 default:
150 _mesa_problem(NULL,
151 "Invalid src register file %d in get_src_register_pointer()",
152 source->File);
153 return NULL;
154 }
155 }
156
157
158 /**
159 * Return a pointer to the 4-element float vector specified by the given
160 * destination register.
161 */
162 static inline GLfloat *
163 get_dst_register_pointer(const struct prog_dst_register *dest,
164 struct gl_program_machine *machine)
165 {
166 static GLfloat dummyReg[4];
167 GLint reg = dest->Index;
168
169 if (dest->RelAddr) {
170 /* add address register value to src index/offset */
171 reg += machine->AddressReg[0][0];
172 if (reg < 0) {
173 return dummyReg;
174 }
175 }
176
177 switch (dest->File) {
178 case PROGRAM_TEMPORARY:
179 if (reg >= MAX_PROGRAM_TEMPS)
180 return dummyReg;
181 return machine->Temporaries[reg];
182
183 case PROGRAM_OUTPUT:
184 if (reg >= MAX_PROGRAM_OUTPUTS)
185 return dummyReg;
186 return machine->Outputs[reg];
187
188 case PROGRAM_WRITE_ONLY:
189 return dummyReg;
190
191 default:
192 _mesa_problem(NULL,
193 "Invalid dest register file %d in get_dst_register_pointer()",
194 dest->File);
195 return NULL;
196 }
197 }
198
199
200
201 /**
202 * Fetch a 4-element float vector from the given source register.
203 * Apply swizzling and negating as needed.
204 */
205 static void
206 fetch_vector4(const struct prog_src_register *source,
207 const struct gl_program_machine *machine, GLfloat result[4])
208 {
209 const GLfloat *src = get_src_register_pointer(source, machine);
210 ASSERT(src);
211
212 if (source->Swizzle == SWIZZLE_NOOP) {
213 /* no swizzling */
214 COPY_4V(result, src);
215 }
216 else {
217 ASSERT(GET_SWZ(source->Swizzle, 0) <= 3);
218 ASSERT(GET_SWZ(source->Swizzle, 1) <= 3);
219 ASSERT(GET_SWZ(source->Swizzle, 2) <= 3);
220 ASSERT(GET_SWZ(source->Swizzle, 3) <= 3);
221 result[0] = src[GET_SWZ(source->Swizzle, 0)];
222 result[1] = src[GET_SWZ(source->Swizzle, 1)];
223 result[2] = src[GET_SWZ(source->Swizzle, 2)];
224 result[3] = src[GET_SWZ(source->Swizzle, 3)];
225 }
226
227 if (source->Abs) {
228 result[0] = FABSF(result[0]);
229 result[1] = FABSF(result[1]);
230 result[2] = FABSF(result[2]);
231 result[3] = FABSF(result[3]);
232 }
233 if (source->Negate) {
234 ASSERT(source->Negate == NEGATE_XYZW);
235 result[0] = -result[0];
236 result[1] = -result[1];
237 result[2] = -result[2];
238 result[3] = -result[3];
239 }
240
241 #ifdef NAN_CHECK
242 assert(!IS_INF_OR_NAN(result[0]));
243 assert(!IS_INF_OR_NAN(result[0]));
244 assert(!IS_INF_OR_NAN(result[0]));
245 assert(!IS_INF_OR_NAN(result[0]));
246 #endif
247 }
248
249
250 /**
251 * Fetch a 4-element uint vector from the given source register.
252 * Apply swizzling but not negation/abs.
253 */
254 static void
255 fetch_vector4ui(const struct prog_src_register *source,
256 const struct gl_program_machine *machine, GLuint result[4])
257 {
258 const GLuint *src = (GLuint *) get_src_register_pointer(source, machine);
259 ASSERT(src);
260
261 if (source->Swizzle == SWIZZLE_NOOP) {
262 /* no swizzling */
263 COPY_4V(result, src);
264 }
265 else {
266 ASSERT(GET_SWZ(source->Swizzle, 0) <= 3);
267 ASSERT(GET_SWZ(source->Swizzle, 1) <= 3);
268 ASSERT(GET_SWZ(source->Swizzle, 2) <= 3);
269 ASSERT(GET_SWZ(source->Swizzle, 3) <= 3);
270 result[0] = src[GET_SWZ(source->Swizzle, 0)];
271 result[1] = src[GET_SWZ(source->Swizzle, 1)];
272 result[2] = src[GET_SWZ(source->Swizzle, 2)];
273 result[3] = src[GET_SWZ(source->Swizzle, 3)];
274 }
275
276 /* Note: no Negate or Abs here */
277 }
278
279
280
281 /**
282 * Fetch the derivative with respect to X or Y for the given register.
283 * XXX this currently only works for fragment program input attribs.
284 */
285 static void
286 fetch_vector4_deriv(struct gl_context * ctx,
287 const struct prog_src_register *source,
288 const struct gl_program_machine *machine,
289 char xOrY, GLfloat result[4])
290 {
291 if (source->File == PROGRAM_INPUT &&
292 source->Index < (GLint) machine->NumDeriv) {
293 const GLint col = machine->CurElement;
294 const GLfloat w = machine->Attribs[FRAG_ATTRIB_WPOS][col][3];
295 const GLfloat invQ = 1.0f / w;
296 GLfloat deriv[4];
297
298 if (xOrY == 'X') {
299 deriv[0] = machine->DerivX[source->Index][0] * invQ;
300 deriv[1] = machine->DerivX[source->Index][1] * invQ;
301 deriv[2] = machine->DerivX[source->Index][2] * invQ;
302 deriv[3] = machine->DerivX[source->Index][3] * invQ;
303 }
304 else {
305 deriv[0] = machine->DerivY[source->Index][0] * invQ;
306 deriv[1] = machine->DerivY[source->Index][1] * invQ;
307 deriv[2] = machine->DerivY[source->Index][2] * invQ;
308 deriv[3] = machine->DerivY[source->Index][3] * invQ;
309 }
310
311 result[0] = deriv[GET_SWZ(source->Swizzle, 0)];
312 result[1] = deriv[GET_SWZ(source->Swizzle, 1)];
313 result[2] = deriv[GET_SWZ(source->Swizzle, 2)];
314 result[3] = deriv[GET_SWZ(source->Swizzle, 3)];
315
316 if (source->Abs) {
317 result[0] = FABSF(result[0]);
318 result[1] = FABSF(result[1]);
319 result[2] = FABSF(result[2]);
320 result[3] = FABSF(result[3]);
321 }
322 if (source->Negate) {
323 ASSERT(source->Negate == NEGATE_XYZW);
324 result[0] = -result[0];
325 result[1] = -result[1];
326 result[2] = -result[2];
327 result[3] = -result[3];
328 }
329 }
330 else {
331 ASSIGN_4V(result, 0.0, 0.0, 0.0, 0.0);
332 }
333 }
334
335
336 /**
337 * As above, but only return result[0] element.
338 */
339 static void
340 fetch_vector1(const struct prog_src_register *source,
341 const struct gl_program_machine *machine, GLfloat result[4])
342 {
343 const GLfloat *src = get_src_register_pointer(source, machine);
344 ASSERT(src);
345
346 result[0] = src[GET_SWZ(source->Swizzle, 0)];
347
348 if (source->Abs) {
349 result[0] = FABSF(result[0]);
350 }
351 if (source->Negate) {
352 result[0] = -result[0];
353 }
354 }
355
356
357 static GLuint
358 fetch_vector1ui(const struct prog_src_register *source,
359 const struct gl_program_machine *machine)
360 {
361 const GLuint *src = (GLuint *) get_src_register_pointer(source, machine);
362 return src[GET_SWZ(source->Swizzle, 0)];
363 }
364
365
366 /**
367 * Fetch texel from texture. Use partial derivatives when possible.
368 */
369 static inline void
370 fetch_texel(struct gl_context *ctx,
371 const struct gl_program_machine *machine,
372 const struct prog_instruction *inst,
373 const GLfloat texcoord[4], GLfloat lodBias,
374 GLfloat color[4])
375 {
376 const GLuint unit = machine->Samplers[inst->TexSrcUnit];
377
378 /* Note: we only have the right derivatives for fragment input attribs.
379 */
380 if (machine->NumDeriv > 0 &&
381 inst->SrcReg[0].File == PROGRAM_INPUT &&
382 inst->SrcReg[0].Index == FRAG_ATTRIB_TEX0 + inst->TexSrcUnit) {
383 /* simple texture fetch for which we should have derivatives */
384 GLuint attr = inst->SrcReg[0].Index;
385 machine->FetchTexelDeriv(ctx, texcoord,
386 machine->DerivX[attr],
387 machine->DerivY[attr],
388 lodBias, unit, color);
389 }
390 else {
391 machine->FetchTexelLod(ctx, texcoord, lodBias, unit, color);
392 }
393 }
394
395
396 /**
397 * Test value against zero and return GT, LT, EQ or UN if NaN.
398 */
399 static inline GLuint
400 generate_cc(float value)
401 {
402 if (value != value)
403 return COND_UN; /* NaN */
404 if (value > 0.0F)
405 return COND_GT;
406 if (value < 0.0F)
407 return COND_LT;
408 return COND_EQ;
409 }
410
411
412 /**
413 * Test if the ccMaskRule is satisfied by the given condition code.
414 * Used to mask destination writes according to the current condition code.
415 */
416 static inline GLboolean
417 test_cc(GLuint condCode, GLuint ccMaskRule)
418 {
419 switch (ccMaskRule) {
420 case COND_EQ: return (condCode == COND_EQ);
421 case COND_NE: return (condCode != COND_EQ);
422 case COND_LT: return (condCode == COND_LT);
423 case COND_GE: return (condCode == COND_GT || condCode == COND_EQ);
424 case COND_LE: return (condCode == COND_LT || condCode == COND_EQ);
425 case COND_GT: return (condCode == COND_GT);
426 case COND_TR: return GL_TRUE;
427 case COND_FL: return GL_FALSE;
428 default: return GL_TRUE;
429 }
430 }
431
432
433 /**
434 * Evaluate the 4 condition codes against a predicate and return GL_TRUE
435 * or GL_FALSE to indicate result.
436 */
437 static inline GLboolean
438 eval_condition(const struct gl_program_machine *machine,
439 const struct prog_instruction *inst)
440 {
441 const GLuint swizzle = inst->DstReg.CondSwizzle;
442 const GLuint condMask = inst->DstReg.CondMask;
443 if (test_cc(machine->CondCodes[GET_SWZ(swizzle, 0)], condMask) ||
444 test_cc(machine->CondCodes[GET_SWZ(swizzle, 1)], condMask) ||
445 test_cc(machine->CondCodes[GET_SWZ(swizzle, 2)], condMask) ||
446 test_cc(machine->CondCodes[GET_SWZ(swizzle, 3)], condMask)) {
447 return GL_TRUE;
448 }
449 else {
450 return GL_FALSE;
451 }
452 }
453
454
455
456 /**
457 * Store 4 floats into a register. Observe the instructions saturate and
458 * set-condition-code flags.
459 */
460 static void
461 store_vector4(const struct prog_instruction *inst,
462 struct gl_program_machine *machine, const GLfloat value[4])
463 {
464 const struct prog_dst_register *dstReg = &(inst->DstReg);
465 const GLboolean clamp = inst->SaturateMode == SATURATE_ZERO_ONE;
466 GLuint writeMask = dstReg->WriteMask;
467 GLfloat clampedValue[4];
468 GLfloat *dst = get_dst_register_pointer(dstReg, machine);
469
470 #if 0
471 if (value[0] > 1.0e10 ||
472 IS_INF_OR_NAN(value[0]) ||
473 IS_INF_OR_NAN(value[1]) ||
474 IS_INF_OR_NAN(value[2]) || IS_INF_OR_NAN(value[3]))
475 printf("store %g %g %g %g\n", value[0], value[1], value[2], value[3]);
476 #endif
477
478 if (clamp) {
479 clampedValue[0] = CLAMP(value[0], 0.0F, 1.0F);
480 clampedValue[1] = CLAMP(value[1], 0.0F, 1.0F);
481 clampedValue[2] = CLAMP(value[2], 0.0F, 1.0F);
482 clampedValue[3] = CLAMP(value[3], 0.0F, 1.0F);
483 value = clampedValue;
484 }
485
486 if (dstReg->CondMask != COND_TR) {
487 /* condition codes may turn off some writes */
488 if (writeMask & WRITEMASK_X) {
489 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 0)],
490 dstReg->CondMask))
491 writeMask &= ~WRITEMASK_X;
492 }
493 if (writeMask & WRITEMASK_Y) {
494 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 1)],
495 dstReg->CondMask))
496 writeMask &= ~WRITEMASK_Y;
497 }
498 if (writeMask & WRITEMASK_Z) {
499 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 2)],
500 dstReg->CondMask))
501 writeMask &= ~WRITEMASK_Z;
502 }
503 if (writeMask & WRITEMASK_W) {
504 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 3)],
505 dstReg->CondMask))
506 writeMask &= ~WRITEMASK_W;
507 }
508 }
509
510 #ifdef NAN_CHECK
511 assert(!IS_INF_OR_NAN(value[0]));
512 assert(!IS_INF_OR_NAN(value[0]));
513 assert(!IS_INF_OR_NAN(value[0]));
514 assert(!IS_INF_OR_NAN(value[0]));
515 #endif
516
517 if (writeMask & WRITEMASK_X)
518 dst[0] = value[0];
519 if (writeMask & WRITEMASK_Y)
520 dst[1] = value[1];
521 if (writeMask & WRITEMASK_Z)
522 dst[2] = value[2];
523 if (writeMask & WRITEMASK_W)
524 dst[3] = value[3];
525
526 if (inst->CondUpdate) {
527 if (writeMask & WRITEMASK_X)
528 machine->CondCodes[0] = generate_cc(value[0]);
529 if (writeMask & WRITEMASK_Y)
530 machine->CondCodes[1] = generate_cc(value[1]);
531 if (writeMask & WRITEMASK_Z)
532 machine->CondCodes[2] = generate_cc(value[2]);
533 if (writeMask & WRITEMASK_W)
534 machine->CondCodes[3] = generate_cc(value[3]);
535 #if DEBUG_PROG
536 printf("CondCodes=(%s,%s,%s,%s) for:\n",
537 _mesa_condcode_string(machine->CondCodes[0]),
538 _mesa_condcode_string(machine->CondCodes[1]),
539 _mesa_condcode_string(machine->CondCodes[2]),
540 _mesa_condcode_string(machine->CondCodes[3]));
541 #endif
542 }
543 }
544
545
546 /**
547 * Store 4 uints into a register. Observe the set-condition-code flags.
548 */
549 static void
550 store_vector4ui(const struct prog_instruction *inst,
551 struct gl_program_machine *machine, const GLuint value[4])
552 {
553 const struct prog_dst_register *dstReg = &(inst->DstReg);
554 GLuint writeMask = dstReg->WriteMask;
555 GLuint *dst = (GLuint *) get_dst_register_pointer(dstReg, machine);
556
557 if (dstReg->CondMask != COND_TR) {
558 /* condition codes may turn off some writes */
559 if (writeMask & WRITEMASK_X) {
560 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 0)],
561 dstReg->CondMask))
562 writeMask &= ~WRITEMASK_X;
563 }
564 if (writeMask & WRITEMASK_Y) {
565 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 1)],
566 dstReg->CondMask))
567 writeMask &= ~WRITEMASK_Y;
568 }
569 if (writeMask & WRITEMASK_Z) {
570 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 2)],
571 dstReg->CondMask))
572 writeMask &= ~WRITEMASK_Z;
573 }
574 if (writeMask & WRITEMASK_W) {
575 if (!test_cc(machine->CondCodes[GET_SWZ(dstReg->CondSwizzle, 3)],
576 dstReg->CondMask))
577 writeMask &= ~WRITEMASK_W;
578 }
579 }
580
581 if (writeMask & WRITEMASK_X)
582 dst[0] = value[0];
583 if (writeMask & WRITEMASK_Y)
584 dst[1] = value[1];
585 if (writeMask & WRITEMASK_Z)
586 dst[2] = value[2];
587 if (writeMask & WRITEMASK_W)
588 dst[3] = value[3];
589
590 if (inst->CondUpdate) {
591 if (writeMask & WRITEMASK_X)
592 machine->CondCodes[0] = generate_cc((float)value[0]);
593 if (writeMask & WRITEMASK_Y)
594 machine->CondCodes[1] = generate_cc((float)value[1]);
595 if (writeMask & WRITEMASK_Z)
596 machine->CondCodes[2] = generate_cc((float)value[2]);
597 if (writeMask & WRITEMASK_W)
598 machine->CondCodes[3] = generate_cc((float)value[3]);
599 #if DEBUG_PROG
600 printf("CondCodes=(%s,%s,%s,%s) for:\n",
601 _mesa_condcode_string(machine->CondCodes[0]),
602 _mesa_condcode_string(machine->CondCodes[1]),
603 _mesa_condcode_string(machine->CondCodes[2]),
604 _mesa_condcode_string(machine->CondCodes[3]));
605 #endif
606 }
607 }
608
609
610
611 /**
612 * Execute the given vertex/fragment program.
613 *
614 * \param ctx rendering context
615 * \param program the program to execute
616 * \param machine machine state (must be initialized)
617 * \return GL_TRUE if program completed or GL_FALSE if program executed KIL.
618 */
619 GLboolean
620 _mesa_execute_program(struct gl_context * ctx,
621 const struct gl_program *program,
622 struct gl_program_machine *machine)
623 {
624 const GLuint numInst = program->NumInstructions;
625 const GLuint maxExec = 65536;
626 GLuint pc, numExec = 0;
627
628 machine->CurProgram = program;
629
630 if (DEBUG_PROG) {
631 printf("execute program %u --------------------\n", program->Id);
632 }
633
634 if (program->Target == GL_VERTEX_PROGRAM_ARB) {
635 machine->EnvParams = ctx->VertexProgram.Parameters;
636 }
637 else {
638 machine->EnvParams = ctx->FragmentProgram.Parameters;
639 }
640
641 for (pc = 0; pc < numInst; pc++) {
642 const struct prog_instruction *inst = program->Instructions + pc;
643
644 if (DEBUG_PROG) {
645 _mesa_print_instruction(inst);
646 }
647
648 switch (inst->Opcode) {
649 case OPCODE_ABS:
650 {
651 GLfloat a[4], result[4];
652 fetch_vector4(&inst->SrcReg[0], machine, a);
653 result[0] = FABSF(a[0]);
654 result[1] = FABSF(a[1]);
655 result[2] = FABSF(a[2]);
656 result[3] = FABSF(a[3]);
657 store_vector4(inst, machine, result);
658 }
659 break;
660 case OPCODE_ADD:
661 {
662 GLfloat a[4], b[4], result[4];
663 fetch_vector4(&inst->SrcReg[0], machine, a);
664 fetch_vector4(&inst->SrcReg[1], machine, b);
665 result[0] = a[0] + b[0];
666 result[1] = a[1] + b[1];
667 result[2] = a[2] + b[2];
668 result[3] = a[3] + b[3];
669 store_vector4(inst, machine, result);
670 if (DEBUG_PROG) {
671 printf("ADD (%g %g %g %g) = (%g %g %g %g) + (%g %g %g %g)\n",
672 result[0], result[1], result[2], result[3],
673 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
674 }
675 }
676 break;
677 case OPCODE_AND: /* bitwise AND */
678 {
679 GLuint a[4], b[4], result[4];
680 fetch_vector4ui(&inst->SrcReg[0], machine, a);
681 fetch_vector4ui(&inst->SrcReg[1], machine, b);
682 result[0] = a[0] & b[0];
683 result[1] = a[1] & b[1];
684 result[2] = a[2] & b[2];
685 result[3] = a[3] & b[3];
686 store_vector4ui(inst, machine, result);
687 }
688 break;
689 case OPCODE_ARL:
690 {
691 GLfloat t[4];
692 fetch_vector4(&inst->SrcReg[0], machine, t);
693 machine->AddressReg[0][0] = IFLOOR(t[0]);
694 if (DEBUG_PROG) {
695 printf("ARL %d\n", machine->AddressReg[0][0]);
696 }
697 }
698 break;
699 case OPCODE_BGNLOOP:
700 /* no-op */
701 ASSERT(program->Instructions[inst->BranchTarget].Opcode
702 == OPCODE_ENDLOOP);
703 break;
704 case OPCODE_ENDLOOP:
705 /* subtract 1 here since pc is incremented by for(pc) loop */
706 ASSERT(program->Instructions[inst->BranchTarget].Opcode
707 == OPCODE_BGNLOOP);
708 pc = inst->BranchTarget - 1; /* go to matching BNGLOOP */
709 break;
710 case OPCODE_BGNSUB: /* begin subroutine */
711 break;
712 case OPCODE_ENDSUB: /* end subroutine */
713 break;
714 case OPCODE_BRK: /* break out of loop (conditional) */
715 ASSERT(program->Instructions[inst->BranchTarget].Opcode
716 == OPCODE_ENDLOOP);
717 if (eval_condition(machine, inst)) {
718 /* break out of loop */
719 /* pc++ at end of for-loop will put us after the ENDLOOP inst */
720 pc = inst->BranchTarget;
721 }
722 break;
723 case OPCODE_CONT: /* continue loop (conditional) */
724 ASSERT(program->Instructions[inst->BranchTarget].Opcode
725 == OPCODE_ENDLOOP);
726 if (eval_condition(machine, inst)) {
727 /* continue at ENDLOOP */
728 /* Subtract 1 here since we'll do pc++ at end of for-loop */
729 pc = inst->BranchTarget - 1;
730 }
731 break;
732 case OPCODE_CAL: /* Call subroutine (conditional) */
733 if (eval_condition(machine, inst)) {
734 /* call the subroutine */
735 if (machine->StackDepth >= MAX_PROGRAM_CALL_DEPTH) {
736 return GL_TRUE; /* Per GL_NV_vertex_program2 spec */
737 }
738 machine->CallStack[machine->StackDepth++] = pc + 1; /* next inst */
739 /* Subtract 1 here since we'll do pc++ at end of for-loop */
740 pc = inst->BranchTarget - 1;
741 }
742 break;
743 case OPCODE_CMP:
744 {
745 GLfloat a[4], b[4], c[4], result[4];
746 fetch_vector4(&inst->SrcReg[0], machine, a);
747 fetch_vector4(&inst->SrcReg[1], machine, b);
748 fetch_vector4(&inst->SrcReg[2], machine, c);
749 result[0] = a[0] < 0.0F ? b[0] : c[0];
750 result[1] = a[1] < 0.0F ? b[1] : c[1];
751 result[2] = a[2] < 0.0F ? b[2] : c[2];
752 result[3] = a[3] < 0.0F ? b[3] : c[3];
753 store_vector4(inst, machine, result);
754 if (DEBUG_PROG) {
755 printf("CMP (%g %g %g %g) = (%g %g %g %g) < 0 ? (%g %g %g %g) : (%g %g %g %g)\n",
756 result[0], result[1], result[2], result[3],
757 a[0], a[1], a[2], a[3],
758 b[0], b[1], b[2], b[3],
759 c[0], c[1], c[2], c[3]);
760 }
761 }
762 break;
763 case OPCODE_COS:
764 {
765 GLfloat a[4], result[4];
766 fetch_vector1(&inst->SrcReg[0], machine, a);
767 result[0] = result[1] = result[2] = result[3]
768 = (GLfloat) cos(a[0]);
769 store_vector4(inst, machine, result);
770 }
771 break;
772 case OPCODE_DDX: /* Partial derivative with respect to X */
773 {
774 GLfloat result[4];
775 fetch_vector4_deriv(ctx, &inst->SrcReg[0], machine,
776 'X', result);
777 store_vector4(inst, machine, result);
778 }
779 break;
780 case OPCODE_DDY: /* Partial derivative with respect to Y */
781 {
782 GLfloat result[4];
783 fetch_vector4_deriv(ctx, &inst->SrcReg[0], machine,
784 'Y', result);
785 store_vector4(inst, machine, result);
786 }
787 break;
788 case OPCODE_DP2:
789 {
790 GLfloat a[4], b[4], result[4];
791 fetch_vector4(&inst->SrcReg[0], machine, a);
792 fetch_vector4(&inst->SrcReg[1], machine, b);
793 result[0] = result[1] = result[2] = result[3] = DOT2(a, b);
794 store_vector4(inst, machine, result);
795 if (DEBUG_PROG) {
796 printf("DP2 %g = (%g %g) . (%g %g)\n",
797 result[0], a[0], a[1], b[0], b[1]);
798 }
799 }
800 break;
801 case OPCODE_DP2A:
802 {
803 GLfloat a[4], b[4], c, result[4];
804 fetch_vector4(&inst->SrcReg[0], machine, a);
805 fetch_vector4(&inst->SrcReg[1], machine, b);
806 fetch_vector1(&inst->SrcReg[1], machine, &c);
807 result[0] = result[1] = result[2] = result[3] = DOT2(a, b) + c;
808 store_vector4(inst, machine, result);
809 if (DEBUG_PROG) {
810 printf("DP2A %g = (%g %g) . (%g %g) + %g\n",
811 result[0], a[0], a[1], b[0], b[1], c);
812 }
813 }
814 break;
815 case OPCODE_DP3:
816 {
817 GLfloat a[4], b[4], result[4];
818 fetch_vector4(&inst->SrcReg[0], machine, a);
819 fetch_vector4(&inst->SrcReg[1], machine, b);
820 result[0] = result[1] = result[2] = result[3] = DOT3(a, b);
821 store_vector4(inst, machine, result);
822 if (DEBUG_PROG) {
823 printf("DP3 %g = (%g %g %g) . (%g %g %g)\n",
824 result[0], a[0], a[1], a[2], b[0], b[1], b[2]);
825 }
826 }
827 break;
828 case OPCODE_DP4:
829 {
830 GLfloat a[4], b[4], result[4];
831 fetch_vector4(&inst->SrcReg[0], machine, a);
832 fetch_vector4(&inst->SrcReg[1], machine, b);
833 result[0] = result[1] = result[2] = result[3] = DOT4(a, b);
834 store_vector4(inst, machine, result);
835 if (DEBUG_PROG) {
836 printf("DP4 %g = (%g, %g %g %g) . (%g, %g %g %g)\n",
837 result[0], a[0], a[1], a[2], a[3],
838 b[0], b[1], b[2], b[3]);
839 }
840 }
841 break;
842 case OPCODE_DPH:
843 {
844 GLfloat a[4], b[4], result[4];
845 fetch_vector4(&inst->SrcReg[0], machine, a);
846 fetch_vector4(&inst->SrcReg[1], machine, b);
847 result[0] = result[1] = result[2] = result[3] = DOT3(a, b) + b[3];
848 store_vector4(inst, machine, result);
849 }
850 break;
851 case OPCODE_DST: /* Distance vector */
852 {
853 GLfloat a[4], b[4], result[4];
854 fetch_vector4(&inst->SrcReg[0], machine, a);
855 fetch_vector4(&inst->SrcReg[1], machine, b);
856 result[0] = 1.0F;
857 result[1] = a[1] * b[1];
858 result[2] = a[2];
859 result[3] = b[3];
860 store_vector4(inst, machine, result);
861 }
862 break;
863 case OPCODE_EXP:
864 {
865 GLfloat t[4], q[4], floor_t0;
866 fetch_vector1(&inst->SrcReg[0], machine, t);
867 floor_t0 = FLOORF(t[0]);
868 if (floor_t0 > FLT_MAX_EXP) {
869 SET_POS_INFINITY(q[0]);
870 SET_POS_INFINITY(q[2]);
871 }
872 else if (floor_t0 < FLT_MIN_EXP) {
873 q[0] = 0.0F;
874 q[2] = 0.0F;
875 }
876 else {
877 q[0] = LDEXPF(1.0, (int) floor_t0);
878 /* Note: GL_NV_vertex_program expects
879 * result.z = result.x * APPX(result.y)
880 * We do what the ARB extension says.
881 */
882 q[2] = (GLfloat) pow(2.0, t[0]);
883 }
884 q[1] = t[0] - floor_t0;
885 q[3] = 1.0F;
886 store_vector4( inst, machine, q );
887 }
888 break;
889 case OPCODE_EX2: /* Exponential base 2 */
890 {
891 GLfloat a[4], result[4], val;
892 fetch_vector1(&inst->SrcReg[0], machine, a);
893 val = (GLfloat) pow(2.0, a[0]);
894 /*
895 if (IS_INF_OR_NAN(val))
896 val = 1.0e10;
897 */
898 result[0] = result[1] = result[2] = result[3] = val;
899 store_vector4(inst, machine, result);
900 }
901 break;
902 case OPCODE_FLR:
903 {
904 GLfloat a[4], result[4];
905 fetch_vector4(&inst->SrcReg[0], machine, a);
906 result[0] = FLOORF(a[0]);
907 result[1] = FLOORF(a[1]);
908 result[2] = FLOORF(a[2]);
909 result[3] = FLOORF(a[3]);
910 store_vector4(inst, machine, result);
911 }
912 break;
913 case OPCODE_FRC:
914 {
915 GLfloat a[4], result[4];
916 fetch_vector4(&inst->SrcReg[0], machine, a);
917 result[0] = a[0] - FLOORF(a[0]);
918 result[1] = a[1] - FLOORF(a[1]);
919 result[2] = a[2] - FLOORF(a[2]);
920 result[3] = a[3] - FLOORF(a[3]);
921 store_vector4(inst, machine, result);
922 }
923 break;
924 case OPCODE_IF:
925 {
926 GLboolean cond;
927 ASSERT(program->Instructions[inst->BranchTarget].Opcode
928 == OPCODE_ELSE ||
929 program->Instructions[inst->BranchTarget].Opcode
930 == OPCODE_ENDIF);
931 /* eval condition */
932 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
933 GLfloat a[4];
934 fetch_vector1(&inst->SrcReg[0], machine, a);
935 cond = (a[0] != 0.0);
936 }
937 else {
938 cond = eval_condition(machine, inst);
939 }
940 if (DEBUG_PROG) {
941 printf("IF: %d\n", cond);
942 }
943 /* do if/else */
944 if (cond) {
945 /* do if-clause (just continue execution) */
946 }
947 else {
948 /* go to the instruction after ELSE or ENDIF */
949 assert(inst->BranchTarget >= 0);
950 pc = inst->BranchTarget;
951 }
952 }
953 break;
954 case OPCODE_ELSE:
955 /* goto ENDIF */
956 ASSERT(program->Instructions[inst->BranchTarget].Opcode
957 == OPCODE_ENDIF);
958 assert(inst->BranchTarget >= 0);
959 pc = inst->BranchTarget;
960 break;
961 case OPCODE_ENDIF:
962 /* nothing */
963 break;
964 case OPCODE_KIL_NV: /* NV_f_p only (conditional) */
965 if (eval_condition(machine, inst)) {
966 return GL_FALSE;
967 }
968 break;
969 case OPCODE_KIL: /* ARB_f_p only */
970 {
971 GLfloat a[4];
972 fetch_vector4(&inst->SrcReg[0], machine, a);
973 if (DEBUG_PROG) {
974 printf("KIL if (%g %g %g %g) <= 0.0\n",
975 a[0], a[1], a[2], a[3]);
976 }
977
978 if (a[0] < 0.0F || a[1] < 0.0F || a[2] < 0.0F || a[3] < 0.0F) {
979 return GL_FALSE;
980 }
981 }
982 break;
983 case OPCODE_LG2: /* log base 2 */
984 {
985 GLfloat a[4], result[4], val;
986 fetch_vector1(&inst->SrcReg[0], machine, a);
987 /* The fast LOG2 macro doesn't meet the precision requirements.
988 */
989 if (a[0] == 0.0F) {
990 val = -FLT_MAX;
991 }
992 else {
993 val = (float)(log(a[0]) * 1.442695F);
994 }
995 result[0] = result[1] = result[2] = result[3] = val;
996 store_vector4(inst, machine, result);
997 }
998 break;
999 case OPCODE_LIT:
1000 {
1001 const GLfloat epsilon = 1.0F / 256.0F; /* from NV VP spec */
1002 GLfloat a[4], result[4];
1003 fetch_vector4(&inst->SrcReg[0], machine, a);
1004 a[0] = MAX2(a[0], 0.0F);
1005 a[1] = MAX2(a[1], 0.0F);
1006 /* XXX ARB version clamps a[3], NV version doesn't */
1007 a[3] = CLAMP(a[3], -(128.0F - epsilon), (128.0F - epsilon));
1008 result[0] = 1.0F;
1009 result[1] = a[0];
1010 /* XXX we could probably just use pow() here */
1011 if (a[0] > 0.0F) {
1012 if (a[1] == 0.0 && a[3] == 0.0)
1013 result[2] = 1.0F;
1014 else
1015 result[2] = (GLfloat) pow(a[1], a[3]);
1016 }
1017 else {
1018 result[2] = 0.0F;
1019 }
1020 result[3] = 1.0F;
1021 store_vector4(inst, machine, result);
1022 if (DEBUG_PROG) {
1023 printf("LIT (%g %g %g %g) : (%g %g %g %g)\n",
1024 result[0], result[1], result[2], result[3],
1025 a[0], a[1], a[2], a[3]);
1026 }
1027 }
1028 break;
1029 case OPCODE_LOG:
1030 {
1031 GLfloat t[4], q[4], abs_t0;
1032 fetch_vector1(&inst->SrcReg[0], machine, t);
1033 abs_t0 = FABSF(t[0]);
1034 if (abs_t0 != 0.0F) {
1035 /* Since we really can't handle infinite values on VMS
1036 * like other OSes we'll use __MAXFLOAT to represent
1037 * infinity. This may need some tweaking.
1038 */
1039 #ifdef VMS
1040 if (abs_t0 == __MAXFLOAT)
1041 #else
1042 if (IS_INF_OR_NAN(abs_t0))
1043 #endif
1044 {
1045 SET_POS_INFINITY(q[0]);
1046 q[1] = 1.0F;
1047 SET_POS_INFINITY(q[2]);
1048 }
1049 else {
1050 int exponent;
1051 GLfloat mantissa = FREXPF(t[0], &exponent);
1052 q[0] = (GLfloat) (exponent - 1);
1053 q[1] = (GLfloat) (2.0 * mantissa); /* map [.5, 1) -> [1, 2) */
1054
1055 /* The fast LOG2 macro doesn't meet the precision
1056 * requirements.
1057 */
1058 q[2] = (float)(log(t[0]) * 1.442695F);
1059 }
1060 }
1061 else {
1062 SET_NEG_INFINITY(q[0]);
1063 q[1] = 1.0F;
1064 SET_NEG_INFINITY(q[2]);
1065 }
1066 q[3] = 1.0;
1067 store_vector4(inst, machine, q);
1068 }
1069 break;
1070 case OPCODE_LRP:
1071 {
1072 GLfloat a[4], b[4], c[4], result[4];
1073 fetch_vector4(&inst->SrcReg[0], machine, a);
1074 fetch_vector4(&inst->SrcReg[1], machine, b);
1075 fetch_vector4(&inst->SrcReg[2], machine, c);
1076 result[0] = a[0] * b[0] + (1.0F - a[0]) * c[0];
1077 result[1] = a[1] * b[1] + (1.0F - a[1]) * c[1];
1078 result[2] = a[2] * b[2] + (1.0F - a[2]) * c[2];
1079 result[3] = a[3] * b[3] + (1.0F - a[3]) * c[3];
1080 store_vector4(inst, machine, result);
1081 if (DEBUG_PROG) {
1082 printf("LRP (%g %g %g %g) = (%g %g %g %g), "
1083 "(%g %g %g %g), (%g %g %g %g)\n",
1084 result[0], result[1], result[2], result[3],
1085 a[0], a[1], a[2], a[3],
1086 b[0], b[1], b[2], b[3], c[0], c[1], c[2], c[3]);
1087 }
1088 }
1089 break;
1090 case OPCODE_MAD:
1091 {
1092 GLfloat a[4], b[4], c[4], result[4];
1093 fetch_vector4(&inst->SrcReg[0], machine, a);
1094 fetch_vector4(&inst->SrcReg[1], machine, b);
1095 fetch_vector4(&inst->SrcReg[2], machine, c);
1096 result[0] = a[0] * b[0] + c[0];
1097 result[1] = a[1] * b[1] + c[1];
1098 result[2] = a[2] * b[2] + c[2];
1099 result[3] = a[3] * b[3] + c[3];
1100 store_vector4(inst, machine, result);
1101 if (DEBUG_PROG) {
1102 printf("MAD (%g %g %g %g) = (%g %g %g %g) * "
1103 "(%g %g %g %g) + (%g %g %g %g)\n",
1104 result[0], result[1], result[2], result[3],
1105 a[0], a[1], a[2], a[3],
1106 b[0], b[1], b[2], b[3], c[0], c[1], c[2], c[3]);
1107 }
1108 }
1109 break;
1110 case OPCODE_MAX:
1111 {
1112 GLfloat a[4], b[4], result[4];
1113 fetch_vector4(&inst->SrcReg[0], machine, a);
1114 fetch_vector4(&inst->SrcReg[1], machine, b);
1115 result[0] = MAX2(a[0], b[0]);
1116 result[1] = MAX2(a[1], b[1]);
1117 result[2] = MAX2(a[2], b[2]);
1118 result[3] = MAX2(a[3], b[3]);
1119 store_vector4(inst, machine, result);
1120 if (DEBUG_PROG) {
1121 printf("MAX (%g %g %g %g) = (%g %g %g %g), (%g %g %g %g)\n",
1122 result[0], result[1], result[2], result[3],
1123 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
1124 }
1125 }
1126 break;
1127 case OPCODE_MIN:
1128 {
1129 GLfloat a[4], b[4], result[4];
1130 fetch_vector4(&inst->SrcReg[0], machine, a);
1131 fetch_vector4(&inst->SrcReg[1], machine, b);
1132 result[0] = MIN2(a[0], b[0]);
1133 result[1] = MIN2(a[1], b[1]);
1134 result[2] = MIN2(a[2], b[2]);
1135 result[3] = MIN2(a[3], b[3]);
1136 store_vector4(inst, machine, result);
1137 }
1138 break;
1139 case OPCODE_MOV:
1140 {
1141 GLfloat result[4];
1142 fetch_vector4(&inst->SrcReg[0], machine, result);
1143 store_vector4(inst, machine, result);
1144 if (DEBUG_PROG) {
1145 printf("MOV (%g %g %g %g)\n",
1146 result[0], result[1], result[2], result[3]);
1147 }
1148 }
1149 break;
1150 case OPCODE_MUL:
1151 {
1152 GLfloat a[4], b[4], result[4];
1153 fetch_vector4(&inst->SrcReg[0], machine, a);
1154 fetch_vector4(&inst->SrcReg[1], machine, b);
1155 result[0] = a[0] * b[0];
1156 result[1] = a[1] * b[1];
1157 result[2] = a[2] * b[2];
1158 result[3] = a[3] * b[3];
1159 store_vector4(inst, machine, result);
1160 if (DEBUG_PROG) {
1161 printf("MUL (%g %g %g %g) = (%g %g %g %g) * (%g %g %g %g)\n",
1162 result[0], result[1], result[2], result[3],
1163 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
1164 }
1165 }
1166 break;
1167 case OPCODE_NOISE1:
1168 {
1169 GLfloat a[4], result[4];
1170 fetch_vector1(&inst->SrcReg[0], machine, a);
1171 result[0] =
1172 result[1] =
1173 result[2] =
1174 result[3] = _mesa_noise1(a[0]);
1175 store_vector4(inst, machine, result);
1176 }
1177 break;
1178 case OPCODE_NOISE2:
1179 {
1180 GLfloat a[4], result[4];
1181 fetch_vector4(&inst->SrcReg[0], machine, a);
1182 result[0] =
1183 result[1] =
1184 result[2] = result[3] = _mesa_noise2(a[0], a[1]);
1185 store_vector4(inst, machine, result);
1186 }
1187 break;
1188 case OPCODE_NOISE3:
1189 {
1190 GLfloat a[4], result[4];
1191 fetch_vector4(&inst->SrcReg[0], machine, a);
1192 result[0] =
1193 result[1] =
1194 result[2] =
1195 result[3] = _mesa_noise3(a[0], a[1], a[2]);
1196 store_vector4(inst, machine, result);
1197 }
1198 break;
1199 case OPCODE_NOISE4:
1200 {
1201 GLfloat a[4], result[4];
1202 fetch_vector4(&inst->SrcReg[0], machine, a);
1203 result[0] =
1204 result[1] =
1205 result[2] =
1206 result[3] = _mesa_noise4(a[0], a[1], a[2], a[3]);
1207 store_vector4(inst, machine, result);
1208 }
1209 break;
1210 case OPCODE_NOP:
1211 break;
1212 case OPCODE_NOT: /* bitwise NOT */
1213 {
1214 GLuint a[4], result[4];
1215 fetch_vector4ui(&inst->SrcReg[0], machine, a);
1216 result[0] = ~a[0];
1217 result[1] = ~a[1];
1218 result[2] = ~a[2];
1219 result[3] = ~a[3];
1220 store_vector4ui(inst, machine, result);
1221 }
1222 break;
1223 case OPCODE_NRM3: /* 3-component normalization */
1224 {
1225 GLfloat a[4], result[4];
1226 GLfloat tmp;
1227 fetch_vector4(&inst->SrcReg[0], machine, a);
1228 tmp = a[0] * a[0] + a[1] * a[1] + a[2] * a[2];
1229 if (tmp != 0.0F)
1230 tmp = INV_SQRTF(tmp);
1231 result[0] = tmp * a[0];
1232 result[1] = tmp * a[1];
1233 result[2] = tmp * a[2];
1234 result[3] = 0.0; /* undefined, but prevent valgrind warnings */
1235 store_vector4(inst, machine, result);
1236 }
1237 break;
1238 case OPCODE_NRM4: /* 4-component normalization */
1239 {
1240 GLfloat a[4], result[4];
1241 GLfloat tmp;
1242 fetch_vector4(&inst->SrcReg[0], machine, a);
1243 tmp = a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3];
1244 if (tmp != 0.0F)
1245 tmp = INV_SQRTF(tmp);
1246 result[0] = tmp * a[0];
1247 result[1] = tmp * a[1];
1248 result[2] = tmp * a[2];
1249 result[3] = tmp * a[3];
1250 store_vector4(inst, machine, result);
1251 }
1252 break;
1253 case OPCODE_OR: /* bitwise OR */
1254 {
1255 GLuint a[4], b[4], result[4];
1256 fetch_vector4ui(&inst->SrcReg[0], machine, a);
1257 fetch_vector4ui(&inst->SrcReg[1], machine, b);
1258 result[0] = a[0] | b[0];
1259 result[1] = a[1] | b[1];
1260 result[2] = a[2] | b[2];
1261 result[3] = a[3] | b[3];
1262 store_vector4ui(inst, machine, result);
1263 }
1264 break;
1265 case OPCODE_PK2H: /* pack two 16-bit floats in one 32-bit float */
1266 {
1267 GLfloat a[4];
1268 GLuint result[4];
1269 GLhalfNV hx, hy;
1270 fetch_vector4(&inst->SrcReg[0], machine, a);
1271 hx = _mesa_float_to_half(a[0]);
1272 hy = _mesa_float_to_half(a[1]);
1273 result[0] =
1274 result[1] =
1275 result[2] =
1276 result[3] = hx | (hy << 16);
1277 store_vector4ui(inst, machine, result);
1278 }
1279 break;
1280 case OPCODE_PK2US: /* pack two GLushorts into one 32-bit float */
1281 {
1282 GLfloat a[4];
1283 GLuint result[4], usx, usy;
1284 fetch_vector4(&inst->SrcReg[0], machine, a);
1285 a[0] = CLAMP(a[0], 0.0F, 1.0F);
1286 a[1] = CLAMP(a[1], 0.0F, 1.0F);
1287 usx = F_TO_I(a[0] * 65535.0F);
1288 usy = F_TO_I(a[1] * 65535.0F);
1289 result[0] =
1290 result[1] =
1291 result[2] =
1292 result[3] = usx | (usy << 16);
1293 store_vector4ui(inst, machine, result);
1294 }
1295 break;
1296 case OPCODE_PK4B: /* pack four GLbytes into one 32-bit float */
1297 {
1298 GLfloat a[4];
1299 GLuint result[4], ubx, uby, ubz, ubw;
1300 fetch_vector4(&inst->SrcReg[0], machine, a);
1301 a[0] = CLAMP(a[0], -128.0F / 127.0F, 1.0F);
1302 a[1] = CLAMP(a[1], -128.0F / 127.0F, 1.0F);
1303 a[2] = CLAMP(a[2], -128.0F / 127.0F, 1.0F);
1304 a[3] = CLAMP(a[3], -128.0F / 127.0F, 1.0F);
1305 ubx = F_TO_I(127.0F * a[0] + 128.0F);
1306 uby = F_TO_I(127.0F * a[1] + 128.0F);
1307 ubz = F_TO_I(127.0F * a[2] + 128.0F);
1308 ubw = F_TO_I(127.0F * a[3] + 128.0F);
1309 result[0] =
1310 result[1] =
1311 result[2] =
1312 result[3] = ubx | (uby << 8) | (ubz << 16) | (ubw << 24);
1313 store_vector4ui(inst, machine, result);
1314 }
1315 break;
1316 case OPCODE_PK4UB: /* pack four GLubytes into one 32-bit float */
1317 {
1318 GLfloat a[4];
1319 GLuint result[4], ubx, uby, ubz, ubw;
1320 fetch_vector4(&inst->SrcReg[0], machine, a);
1321 a[0] = CLAMP(a[0], 0.0F, 1.0F);
1322 a[1] = CLAMP(a[1], 0.0F, 1.0F);
1323 a[2] = CLAMP(a[2], 0.0F, 1.0F);
1324 a[3] = CLAMP(a[3], 0.0F, 1.0F);
1325 ubx = F_TO_I(255.0F * a[0]);
1326 uby = F_TO_I(255.0F * a[1]);
1327 ubz = F_TO_I(255.0F * a[2]);
1328 ubw = F_TO_I(255.0F * a[3]);
1329 result[0] =
1330 result[1] =
1331 result[2] =
1332 result[3] = ubx | (uby << 8) | (ubz << 16) | (ubw << 24);
1333 store_vector4ui(inst, machine, result);
1334 }
1335 break;
1336 case OPCODE_POW:
1337 {
1338 GLfloat a[4], b[4], result[4];
1339 fetch_vector1(&inst->SrcReg[0], machine, a);
1340 fetch_vector1(&inst->SrcReg[1], machine, b);
1341 result[0] = result[1] = result[2] = result[3]
1342 = (GLfloat) pow(a[0], b[0]);
1343 store_vector4(inst, machine, result);
1344 }
1345 break;
1346
1347 case OPCODE_RCP:
1348 {
1349 GLfloat a[4], result[4];
1350 fetch_vector1(&inst->SrcReg[0], machine, a);
1351 if (DEBUG_PROG) {
1352 if (a[0] == 0)
1353 printf("RCP(0)\n");
1354 else if (IS_INF_OR_NAN(a[0]))
1355 printf("RCP(inf)\n");
1356 }
1357 result[0] = result[1] = result[2] = result[3] = 1.0F / a[0];
1358 store_vector4(inst, machine, result);
1359 }
1360 break;
1361 case OPCODE_RET: /* return from subroutine (conditional) */
1362 if (eval_condition(machine, inst)) {
1363 if (machine->StackDepth == 0) {
1364 return GL_TRUE; /* Per GL_NV_vertex_program2 spec */
1365 }
1366 /* subtract one because of pc++ in the for loop */
1367 pc = machine->CallStack[--machine->StackDepth] - 1;
1368 }
1369 break;
1370 case OPCODE_RFL: /* reflection vector */
1371 {
1372 GLfloat axis[4], dir[4], result[4], tmpX, tmpW;
1373 fetch_vector4(&inst->SrcReg[0], machine, axis);
1374 fetch_vector4(&inst->SrcReg[1], machine, dir);
1375 tmpW = DOT3(axis, axis);
1376 tmpX = (2.0F * DOT3(axis, dir)) / tmpW;
1377 result[0] = tmpX * axis[0] - dir[0];
1378 result[1] = tmpX * axis[1] - dir[1];
1379 result[2] = tmpX * axis[2] - dir[2];
1380 /* result[3] is never written! XXX enforce in parser! */
1381 store_vector4(inst, machine, result);
1382 }
1383 break;
1384 case OPCODE_RSQ: /* 1 / sqrt() */
1385 {
1386 GLfloat a[4], result[4];
1387 fetch_vector1(&inst->SrcReg[0], machine, a);
1388 a[0] = FABSF(a[0]);
1389 result[0] = result[1] = result[2] = result[3] = INV_SQRTF(a[0]);
1390 store_vector4(inst, machine, result);
1391 if (DEBUG_PROG) {
1392 printf("RSQ %g = 1/sqrt(|%g|)\n", result[0], a[0]);
1393 }
1394 }
1395 break;
1396 case OPCODE_SCS: /* sine and cos */
1397 {
1398 GLfloat a[4], result[4];
1399 fetch_vector1(&inst->SrcReg[0], machine, a);
1400 result[0] = (GLfloat) cos(a[0]);
1401 result[1] = (GLfloat) sin(a[0]);
1402 result[2] = 0.0; /* undefined! */
1403 result[3] = 0.0; /* undefined! */
1404 store_vector4(inst, machine, result);
1405 }
1406 break;
1407 case OPCODE_SEQ: /* set on equal */
1408 {
1409 GLfloat a[4], b[4], result[4];
1410 fetch_vector4(&inst->SrcReg[0], machine, a);
1411 fetch_vector4(&inst->SrcReg[1], machine, b);
1412 result[0] = (a[0] == b[0]) ? 1.0F : 0.0F;
1413 result[1] = (a[1] == b[1]) ? 1.0F : 0.0F;
1414 result[2] = (a[2] == b[2]) ? 1.0F : 0.0F;
1415 result[3] = (a[3] == b[3]) ? 1.0F : 0.0F;
1416 store_vector4(inst, machine, result);
1417 if (DEBUG_PROG) {
1418 printf("SEQ (%g %g %g %g) = (%g %g %g %g) == (%g %g %g %g)\n",
1419 result[0], result[1], result[2], result[3],
1420 a[0], a[1], a[2], a[3],
1421 b[0], b[1], b[2], b[3]);
1422 }
1423 }
1424 break;
1425 case OPCODE_SFL: /* set false, operands ignored */
1426 {
1427 static const GLfloat result[4] = { 0.0F, 0.0F, 0.0F, 0.0F };
1428 store_vector4(inst, machine, result);
1429 }
1430 break;
1431 case OPCODE_SGE: /* set on greater or equal */
1432 {
1433 GLfloat a[4], b[4], result[4];
1434 fetch_vector4(&inst->SrcReg[0], machine, a);
1435 fetch_vector4(&inst->SrcReg[1], machine, b);
1436 result[0] = (a[0] >= b[0]) ? 1.0F : 0.0F;
1437 result[1] = (a[1] >= b[1]) ? 1.0F : 0.0F;
1438 result[2] = (a[2] >= b[2]) ? 1.0F : 0.0F;
1439 result[3] = (a[3] >= b[3]) ? 1.0F : 0.0F;
1440 store_vector4(inst, machine, result);
1441 if (DEBUG_PROG) {
1442 printf("SGE (%g %g %g %g) = (%g %g %g %g) >= (%g %g %g %g)\n",
1443 result[0], result[1], result[2], result[3],
1444 a[0], a[1], a[2], a[3],
1445 b[0], b[1], b[2], b[3]);
1446 }
1447 }
1448 break;
1449 case OPCODE_SGT: /* set on greater */
1450 {
1451 GLfloat a[4], b[4], result[4];
1452 fetch_vector4(&inst->SrcReg[0], machine, a);
1453 fetch_vector4(&inst->SrcReg[1], machine, b);
1454 result[0] = (a[0] > b[0]) ? 1.0F : 0.0F;
1455 result[1] = (a[1] > b[1]) ? 1.0F : 0.0F;
1456 result[2] = (a[2] > b[2]) ? 1.0F : 0.0F;
1457 result[3] = (a[3] > b[3]) ? 1.0F : 0.0F;
1458 store_vector4(inst, machine, result);
1459 if (DEBUG_PROG) {
1460 printf("SGT (%g %g %g %g) = (%g %g %g %g) > (%g %g %g %g)\n",
1461 result[0], result[1], result[2], result[3],
1462 a[0], a[1], a[2], a[3],
1463 b[0], b[1], b[2], b[3]);
1464 }
1465 }
1466 break;
1467 case OPCODE_SIN:
1468 {
1469 GLfloat a[4], result[4];
1470 fetch_vector1(&inst->SrcReg[0], machine, a);
1471 result[0] = result[1] = result[2] = result[3]
1472 = (GLfloat) sin(a[0]);
1473 store_vector4(inst, machine, result);
1474 }
1475 break;
1476 case OPCODE_SLE: /* set on less or equal */
1477 {
1478 GLfloat a[4], b[4], result[4];
1479 fetch_vector4(&inst->SrcReg[0], machine, a);
1480 fetch_vector4(&inst->SrcReg[1], machine, b);
1481 result[0] = (a[0] <= b[0]) ? 1.0F : 0.0F;
1482 result[1] = (a[1] <= b[1]) ? 1.0F : 0.0F;
1483 result[2] = (a[2] <= b[2]) ? 1.0F : 0.0F;
1484 result[3] = (a[3] <= b[3]) ? 1.0F : 0.0F;
1485 store_vector4(inst, machine, result);
1486 if (DEBUG_PROG) {
1487 printf("SLE (%g %g %g %g) = (%g %g %g %g) <= (%g %g %g %g)\n",
1488 result[0], result[1], result[2], result[3],
1489 a[0], a[1], a[2], a[3],
1490 b[0], b[1], b[2], b[3]);
1491 }
1492 }
1493 break;
1494 case OPCODE_SLT: /* set on less */
1495 {
1496 GLfloat a[4], b[4], result[4];
1497 fetch_vector4(&inst->SrcReg[0], machine, a);
1498 fetch_vector4(&inst->SrcReg[1], machine, b);
1499 result[0] = (a[0] < b[0]) ? 1.0F : 0.0F;
1500 result[1] = (a[1] < b[1]) ? 1.0F : 0.0F;
1501 result[2] = (a[2] < b[2]) ? 1.0F : 0.0F;
1502 result[3] = (a[3] < b[3]) ? 1.0F : 0.0F;
1503 store_vector4(inst, machine, result);
1504 if (DEBUG_PROG) {
1505 printf("SLT (%g %g %g %g) = (%g %g %g %g) < (%g %g %g %g)\n",
1506 result[0], result[1], result[2], result[3],
1507 a[0], a[1], a[2], a[3],
1508 b[0], b[1], b[2], b[3]);
1509 }
1510 }
1511 break;
1512 case OPCODE_SNE: /* set on not equal */
1513 {
1514 GLfloat a[4], b[4], result[4];
1515 fetch_vector4(&inst->SrcReg[0], machine, a);
1516 fetch_vector4(&inst->SrcReg[1], machine, b);
1517 result[0] = (a[0] != b[0]) ? 1.0F : 0.0F;
1518 result[1] = (a[1] != b[1]) ? 1.0F : 0.0F;
1519 result[2] = (a[2] != b[2]) ? 1.0F : 0.0F;
1520 result[3] = (a[3] != b[3]) ? 1.0F : 0.0F;
1521 store_vector4(inst, machine, result);
1522 if (DEBUG_PROG) {
1523 printf("SNE (%g %g %g %g) = (%g %g %g %g) != (%g %g %g %g)\n",
1524 result[0], result[1], result[2], result[3],
1525 a[0], a[1], a[2], a[3],
1526 b[0], b[1], b[2], b[3]);
1527 }
1528 }
1529 break;
1530 case OPCODE_SSG: /* set sign (-1, 0 or +1) */
1531 {
1532 GLfloat a[4], result[4];
1533 fetch_vector4(&inst->SrcReg[0], machine, a);
1534 result[0] = (GLfloat) ((a[0] > 0.0F) - (a[0] < 0.0F));
1535 result[1] = (GLfloat) ((a[1] > 0.0F) - (a[1] < 0.0F));
1536 result[2] = (GLfloat) ((a[2] > 0.0F) - (a[2] < 0.0F));
1537 result[3] = (GLfloat) ((a[3] > 0.0F) - (a[3] < 0.0F));
1538 store_vector4(inst, machine, result);
1539 }
1540 break;
1541 case OPCODE_STR: /* set true, operands ignored */
1542 {
1543 static const GLfloat result[4] = { 1.0F, 1.0F, 1.0F, 1.0F };
1544 store_vector4(inst, machine, result);
1545 }
1546 break;
1547 case OPCODE_SUB:
1548 {
1549 GLfloat a[4], b[4], result[4];
1550 fetch_vector4(&inst->SrcReg[0], machine, a);
1551 fetch_vector4(&inst->SrcReg[1], machine, b);
1552 result[0] = a[0] - b[0];
1553 result[1] = a[1] - b[1];
1554 result[2] = a[2] - b[2];
1555 result[3] = a[3] - b[3];
1556 store_vector4(inst, machine, result);
1557 if (DEBUG_PROG) {
1558 printf("SUB (%g %g %g %g) = (%g %g %g %g) - (%g %g %g %g)\n",
1559 result[0], result[1], result[2], result[3],
1560 a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3]);
1561 }
1562 }
1563 break;
1564 case OPCODE_SWZ: /* extended swizzle */
1565 {
1566 const struct prog_src_register *source = &inst->SrcReg[0];
1567 const GLfloat *src = get_src_register_pointer(source, machine);
1568 GLfloat result[4];
1569 GLuint i;
1570 for (i = 0; i < 4; i++) {
1571 const GLuint swz = GET_SWZ(source->Swizzle, i);
1572 if (swz == SWIZZLE_ZERO)
1573 result[i] = 0.0;
1574 else if (swz == SWIZZLE_ONE)
1575 result[i] = 1.0;
1576 else {
1577 ASSERT(swz >= 0);
1578 ASSERT(swz <= 3);
1579 result[i] = src[swz];
1580 }
1581 if (source->Negate & (1 << i))
1582 result[i] = -result[i];
1583 }
1584 store_vector4(inst, machine, result);
1585 }
1586 break;
1587 case OPCODE_TEX: /* Both ARB and NV frag prog */
1588 /* Simple texel lookup */
1589 {
1590 GLfloat texcoord[4], color[4];
1591 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1592
1593 /* For TEX, texcoord.Q should not be used and its value should not
1594 * matter (at most, we pass coord.xyz to texture3D() in GLSL).
1595 * Set Q=1 so that FetchTexelDeriv() doesn't get a garbage value
1596 * which is effectively what happens when the texcoord swizzle
1597 * is .xyzz
1598 */
1599 texcoord[3] = 1.0f;
1600
1601 fetch_texel(ctx, machine, inst, texcoord, 0.0, color);
1602
1603 if (DEBUG_PROG) {
1604 printf("TEX (%g, %g, %g, %g) = texture[%d][%g, %g, %g, %g]\n",
1605 color[0], color[1], color[2], color[3],
1606 inst->TexSrcUnit,
1607 texcoord[0], texcoord[1], texcoord[2], texcoord[3]);
1608 }
1609 store_vector4(inst, machine, color);
1610 }
1611 break;
1612 case OPCODE_TXB: /* GL_ARB_fragment_program only */
1613 /* Texel lookup with LOD bias */
1614 {
1615 GLfloat texcoord[4], color[4], lodBias;
1616
1617 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1618
1619 /* texcoord[3] is the bias to add to lambda */
1620 lodBias = texcoord[3];
1621
1622 fetch_texel(ctx, machine, inst, texcoord, lodBias, color);
1623
1624 if (DEBUG_PROG) {
1625 printf("TXB (%g, %g, %g, %g) = texture[%d][%g %g %g %g]"
1626 " bias %g\n",
1627 color[0], color[1], color[2], color[3],
1628 inst->TexSrcUnit,
1629 texcoord[0],
1630 texcoord[1],
1631 texcoord[2],
1632 texcoord[3],
1633 lodBias);
1634 }
1635
1636 store_vector4(inst, machine, color);
1637 }
1638 break;
1639 case OPCODE_TXD: /* GL_NV_fragment_program only */
1640 /* Texture lookup w/ partial derivatives for LOD */
1641 {
1642 GLfloat texcoord[4], dtdx[4], dtdy[4], color[4];
1643 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1644 fetch_vector4(&inst->SrcReg[1], machine, dtdx);
1645 fetch_vector4(&inst->SrcReg[2], machine, dtdy);
1646 machine->FetchTexelDeriv(ctx, texcoord, dtdx, dtdy,
1647 0.0, /* lodBias */
1648 inst->TexSrcUnit, color);
1649 store_vector4(inst, machine, color);
1650 }
1651 break;
1652 case OPCODE_TXL:
1653 /* Texel lookup with explicit LOD */
1654 {
1655 GLfloat texcoord[4], color[4], lod;
1656
1657 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1658
1659 /* texcoord[3] is the LOD */
1660 lod = texcoord[3];
1661
1662 machine->FetchTexelLod(ctx, texcoord, lod,
1663 machine->Samplers[inst->TexSrcUnit], color);
1664
1665 store_vector4(inst, machine, color);
1666 }
1667 break;
1668 case OPCODE_TXP: /* GL_ARB_fragment_program only */
1669 /* Texture lookup w/ projective divide */
1670 {
1671 GLfloat texcoord[4], color[4];
1672
1673 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1674 /* Not so sure about this test - if texcoord[3] is
1675 * zero, we'd probably be fine except for an ASSERT in
1676 * IROUND_POS() which gets triggered by the inf values created.
1677 */
1678 if (texcoord[3] != 0.0) {
1679 texcoord[0] /= texcoord[3];
1680 texcoord[1] /= texcoord[3];
1681 texcoord[2] /= texcoord[3];
1682 }
1683
1684 fetch_texel(ctx, machine, inst, texcoord, 0.0, color);
1685
1686 store_vector4(inst, machine, color);
1687 }
1688 break;
1689 case OPCODE_TXP_NV: /* GL_NV_fragment_program only */
1690 /* Texture lookup w/ projective divide, as above, but do not
1691 * do the divide by w if sampling from a cube map.
1692 */
1693 {
1694 GLfloat texcoord[4], color[4];
1695
1696 fetch_vector4(&inst->SrcReg[0], machine, texcoord);
1697 if (inst->TexSrcTarget != TEXTURE_CUBE_INDEX &&
1698 texcoord[3] != 0.0) {
1699 texcoord[0] /= texcoord[3];
1700 texcoord[1] /= texcoord[3];
1701 texcoord[2] /= texcoord[3];
1702 }
1703
1704 fetch_texel(ctx, machine, inst, texcoord, 0.0, color);
1705
1706 store_vector4(inst, machine, color);
1707 }
1708 break;
1709 case OPCODE_TRUNC: /* truncate toward zero */
1710 {
1711 GLfloat a[4], result[4];
1712 fetch_vector4(&inst->SrcReg[0], machine, a);
1713 result[0] = (GLfloat) (GLint) a[0];
1714 result[1] = (GLfloat) (GLint) a[1];
1715 result[2] = (GLfloat) (GLint) a[2];
1716 result[3] = (GLfloat) (GLint) a[3];
1717 store_vector4(inst, machine, result);
1718 }
1719 break;
1720 case OPCODE_UP2H: /* unpack two 16-bit floats */
1721 {
1722 const GLuint raw = fetch_vector1ui(&inst->SrcReg[0], machine);
1723 GLfloat result[4];
1724 GLushort hx, hy;
1725 hx = raw & 0xffff;
1726 hy = raw >> 16;
1727 result[0] = result[2] = _mesa_half_to_float(hx);
1728 result[1] = result[3] = _mesa_half_to_float(hy);
1729 store_vector4(inst, machine, result);
1730 }
1731 break;
1732 case OPCODE_UP2US: /* unpack two GLushorts */
1733 {
1734 const GLuint raw = fetch_vector1ui(&inst->SrcReg[0], machine);
1735 GLfloat result[4];
1736 GLushort usx, usy;
1737 usx = raw & 0xffff;
1738 usy = raw >> 16;
1739 result[0] = result[2] = usx * (1.0f / 65535.0f);
1740 result[1] = result[3] = usy * (1.0f / 65535.0f);
1741 store_vector4(inst, machine, result);
1742 }
1743 break;
1744 case OPCODE_UP4B: /* unpack four GLbytes */
1745 {
1746 const GLuint raw = fetch_vector1ui(&inst->SrcReg[0], machine);
1747 GLfloat result[4];
1748 result[0] = (((raw >> 0) & 0xff) - 128) / 127.0F;
1749 result[1] = (((raw >> 8) & 0xff) - 128) / 127.0F;
1750 result[2] = (((raw >> 16) & 0xff) - 128) / 127.0F;
1751 result[3] = (((raw >> 24) & 0xff) - 128) / 127.0F;
1752 store_vector4(inst, machine, result);
1753 }
1754 break;
1755 case OPCODE_UP4UB: /* unpack four GLubytes */
1756 {
1757 const GLuint raw = fetch_vector1ui(&inst->SrcReg[0], machine);
1758 GLfloat result[4];
1759 result[0] = ((raw >> 0) & 0xff) / 255.0F;
1760 result[1] = ((raw >> 8) & 0xff) / 255.0F;
1761 result[2] = ((raw >> 16) & 0xff) / 255.0F;
1762 result[3] = ((raw >> 24) & 0xff) / 255.0F;
1763 store_vector4(inst, machine, result);
1764 }
1765 break;
1766 case OPCODE_XOR: /* bitwise XOR */
1767 {
1768 GLuint a[4], b[4], result[4];
1769 fetch_vector4ui(&inst->SrcReg[0], machine, a);
1770 fetch_vector4ui(&inst->SrcReg[1], machine, b);
1771 result[0] = a[0] ^ b[0];
1772 result[1] = a[1] ^ b[1];
1773 result[2] = a[2] ^ b[2];
1774 result[3] = a[3] ^ b[3];
1775 store_vector4ui(inst, machine, result);
1776 }
1777 break;
1778 case OPCODE_XPD: /* cross product */
1779 {
1780 GLfloat a[4], b[4], result[4];
1781 fetch_vector4(&inst->SrcReg[0], machine, a);
1782 fetch_vector4(&inst->SrcReg[1], machine, b);
1783 result[0] = a[1] * b[2] - a[2] * b[1];
1784 result[1] = a[2] * b[0] - a[0] * b[2];
1785 result[2] = a[0] * b[1] - a[1] * b[0];
1786 result[3] = 1.0;
1787 store_vector4(inst, machine, result);
1788 if (DEBUG_PROG) {
1789 printf("XPD (%g %g %g %g) = (%g %g %g) X (%g %g %g)\n",
1790 result[0], result[1], result[2], result[3],
1791 a[0], a[1], a[2], b[0], b[1], b[2]);
1792 }
1793 }
1794 break;
1795 case OPCODE_X2D: /* 2-D matrix transform */
1796 {
1797 GLfloat a[4], b[4], c[4], result[4];
1798 fetch_vector4(&inst->SrcReg[0], machine, a);
1799 fetch_vector4(&inst->SrcReg[1], machine, b);
1800 fetch_vector4(&inst->SrcReg[2], machine, c);
1801 result[0] = a[0] + b[0] * c[0] + b[1] * c[1];
1802 result[1] = a[1] + b[0] * c[2] + b[1] * c[3];
1803 result[2] = a[2] + b[0] * c[0] + b[1] * c[1];
1804 result[3] = a[3] + b[0] * c[2] + b[1] * c[3];
1805 store_vector4(inst, machine, result);
1806 }
1807 break;
1808 case OPCODE_PRINT:
1809 {
1810 if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
1811 GLfloat a[4];
1812 fetch_vector4(&inst->SrcReg[0], machine, a);
1813 printf("%s%g, %g, %g, %g\n", (const char *) inst->Data,
1814 a[0], a[1], a[2], a[3]);
1815 }
1816 else {
1817 printf("%s\n", (const char *) inst->Data);
1818 }
1819 }
1820 break;
1821 case OPCODE_END:
1822 return GL_TRUE;
1823 default:
1824 _mesa_problem(ctx, "Bad opcode %d in _mesa_execute_program",
1825 inst->Opcode);
1826 return GL_TRUE; /* return value doesn't matter */
1827 }
1828
1829 numExec++;
1830 if (numExec > maxExec) {
1831 static GLboolean reported = GL_FALSE;
1832 if (!reported) {
1833 _mesa_problem(ctx, "Infinite loop detected in fragment program");
1834 reported = GL_TRUE;
1835 }
1836 return GL_TRUE;
1837 }
1838
1839 } /* for pc */
1840
1841 return GL_TRUE;
1842 }