GLvoid
_slang_code_object_ctr (slang_code_object *self)
{
- _slang_code_unit_ctr (&self->builtin[0], self);
- _slang_code_unit_ctr (&self->builtin[1], self);
- _slang_code_unit_ctr (&self->builtin[2], self);
+ GLuint i;
+
+ for (i = 0; i < SLANG_BUILTIN_TOTAL; i++)
+ _slang_code_unit_ctr (&self->builtin[i], self);
_slang_code_unit_ctr (&self->unit, self);
_slang_assembly_file_ctr (&self->assembly);
slang_machine_ctr (&self->machine);
GLvoid
_slang_code_object_dtr (slang_code_object *self)
{
- _slang_code_unit_dtr (&self->builtin[0]);
- _slang_code_unit_dtr (&self->builtin[1]);
- _slang_code_unit_dtr (&self->builtin[2]);
+ GLuint i;
+
+ for (i = 0; i < SLANG_BUILTIN_TOTAL; i++)
+ _slang_code_unit_dtr (&self->builtin[i]);
_slang_code_unit_dtr (&self->unit);
slang_assembly_file_destruct (&self->assembly);
slang_machine_dtr (&self->machine);
}
/* initialize global variable */
- if (C->global_scope && var->initializer != NULL)
- {
- slang_assemble_ctx A;
-
- A.file = O->assembly;
- A.mach = O->machine;
- A.atoms = C->atoms;
- A.space.funcs = O->funs;
- A.space.structs = O->structs;
- A.space.vars = O->vars;
- if (!initialize_global (&A, var))
- return 0;
+ if (C->global_scope) {
+ if (var->initializer != NULL) {
+ slang_assemble_ctx A;
+
+ A.file = O->assembly;
+ A.mach = O->machine;
+ A.atoms = C->atoms;
+ A.space.funcs = O->funs;
+ A.space.structs = O->structs;
+ A.space.vars = O->vars;
+ if (!initialize_global (&A, var))
+ return 0;
+ }
+ else {
+ _mesa_memset ((GLubyte *) (O->machine->mem) + var->address, 0, var->size);
+ }
}
return 1;
}
return 1;
}
-#define BUILTIN_CORE 0
-#define BUILTIN_COMMON 1
-#define BUILTIN_TARGET 2
-#define BUILTIN_TOTAL 3
-
static GLboolean
compile_binary (const byte *prod, slang_code_unit *unit, slang_unit_type type,
slang_info_log *infolog, slang_code_unit *builtin, slang_code_unit *downlink)
}
/* syntax is okay - translate it to internal representation */
- if (!compile_binary (prod, unit, type, infolog, builtin, &builtin[BUILTIN_TARGET])) {
+ if (!compile_binary (prod, unit, type, infolog, builtin, &builtin[SLANG_BUILTIN_TOTAL - 1])) {
grammar_alloc_free (prod);
return GL_FALSE;
}
#include "library/slang_vertex_builtin_gc.h"
};
+#if defined(USE_X86_ASM) || defined(SLANG_X86)
+static const byte slang_builtin_vec4_gc[] = {
+#include "library/slang_builtin_vec4_gc.h"
+};
+#endif
+
static GLboolean
compile_object (grammar *id, const char *source, slang_code_object *object, slang_unit_type type,
slang_info_log *infolog)
if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader)
{
/* compile core functionality first */
- if (!compile_binary (slang_core_gc, &object->builtin[BUILTIN_CORE],
+ if (!compile_binary (slang_core_gc, &object->builtin[SLANG_BUILTIN_CORE],
slang_unit_fragment_builtin, infolog, NULL, NULL))
return GL_FALSE;
/* compile common functions and variables, link to core */
- if (!compile_binary (slang_common_builtin_gc, &object->builtin[BUILTIN_COMMON],
+ if (!compile_binary (slang_common_builtin_gc, &object->builtin[SLANG_BUILTIN_COMMON],
slang_unit_fragment_builtin, infolog, NULL,
- &object->builtin[BUILTIN_CORE]))
+ &object->builtin[SLANG_BUILTIN_CORE]))
return GL_FALSE;
/* compile target-specific functions and variables, link to common */
if (type == slang_unit_fragment_shader)
{
- if (!compile_binary (slang_fragment_builtin_gc, &object->builtin[BUILTIN_TARGET],
+ if (!compile_binary (slang_fragment_builtin_gc, &object->builtin[SLANG_BUILTIN_TARGET],
slang_unit_fragment_builtin, infolog, NULL,
- &object->builtin[BUILTIN_COMMON]))
+ &object->builtin[SLANG_BUILTIN_COMMON]))
return GL_FALSE;
}
else if (type == slang_unit_vertex_shader)
{
- if (!compile_binary (slang_vertex_builtin_gc, &object->builtin[BUILTIN_TARGET],
+ if (!compile_binary (slang_vertex_builtin_gc, &object->builtin[SLANG_BUILTIN_TARGET],
slang_unit_vertex_builtin, infolog, NULL,
- &object->builtin[BUILTIN_COMMON]))
+ &object->builtin[SLANG_BUILTIN_COMMON]))
return GL_FALSE;
}
+#if defined(USE_X86_ASM) || defined(SLANG_X86)
+ /* compile x86 4-component vector overrides, link to target */
+ if (!compile_binary (slang_builtin_vec4_gc, &object->builtin[SLANG_BUILTIN_VEC4],
+ slang_unit_fragment_builtin, infolog, NULL,
+ &object->builtin[SLANG_BUILTIN_TARGET]))
+ return GL_FALSE;
+#endif
+
/* disable language extensions */
grammar_set_reg8 (*id, (const byte *) "parsing_builtin", 0);
builtins = object->builtin;
struct x86_reg r_st1;
struct x86_reg r_st2;
struct x86_reg r_st3;
+ struct x86_reg r_st4;
fixup *fixups;
GLuint fixup_count;
GLubyte **labels;
case slang_asm_exit:
x86_jmp (&G->f, G->l_exit);
break;
- /* mesa-specific extensions */
+ /* GL_MESA_shader_debug */
case slang_asm_float_print:
/* TODO: use push imm32 */
x86_mov_reg_imm (&G->f, G->r_eax, (GLint) (infolog));
x86_call (&G->f, (GLubyte *) do_print_bool);
x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 4));
break;
+ /* vec4 */
+ case slang_asm_float_to_vec4:
+ /* [vec4] | float */
+ x87_fld (&G->f, x86_deref (G->r_esp));
+ x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 4));
+ x86_mov (&G->f, G->r_eax, x86_deref (G->r_esp));
+ x87_fst (&G->f, x86_make_disp (G->r_eax, 12));
+ x87_fst (&G->f, x86_make_disp (G->r_eax, 8));
+ x87_fst (&G->f, x86_make_disp (G->r_eax, 4));
+ x87_fstp (&G->f, x86_deref (G->r_eax));
+ break;
+ case slang_asm_vec4_add:
+ /* [vec4] | vec4 */
+ x87_fld (&G->f, x86_deref (G->r_esp));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 4));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 8));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 12));
+ x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 16));
+ x86_mov (&G->f, G->r_eax, x86_deref (G->r_esp));
+ x87_fld (&G->f, x86_deref (G->r_eax));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 4));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 8));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 12));
+ x87_faddp (&G->f, G->r_st4);
+ x87_faddp (&G->f, G->r_st4);
+ x87_faddp (&G->f, G->r_st4);
+ x87_faddp (&G->f, G->r_st4);
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 12));
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 8));
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 4));
+ x87_fstp (&G->f, x86_deref (G->r_eax));
+ break;
+ case slang_asm_vec4_subtract:
+ /* [vec4] | vec4 */
+ x86_mov (&G->f, G->r_eax, x86_make_disp (G->r_esp, 16));
+ x87_fld (&G->f, x86_deref (G->r_eax));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 4));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 8));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 12));
+ x87_fld (&G->f, x86_deref (G->r_esp));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 4));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 8));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 12));
+ x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 16));
+ x87_fsubp (&G->f, G->r_st4);
+ x87_fsubp (&G->f, G->r_st4);
+ x87_fsubp (&G->f, G->r_st4);
+ x87_fsubp (&G->f, G->r_st4);
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 12));
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 8));
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 4));
+ x87_fstp (&G->f, x86_deref (G->r_eax));
+ break;
+ case slang_asm_vec4_multiply:
+ /* [vec4] | vec4 */
+ x87_fld (&G->f, x86_deref (G->r_esp));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 4));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 8));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 12));
+ x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 16));
+ x86_mov (&G->f, G->r_eax, x86_deref (G->r_esp));
+ x87_fld (&G->f, x86_deref (G->r_eax));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 4));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 8));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 12));
+ x87_fmulp (&G->f, G->r_st4);
+ x87_fmulp (&G->f, G->r_st4);
+ x87_fmulp (&G->f, G->r_st4);
+ x87_fmulp (&G->f, G->r_st4);
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 12));
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 8));
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 4));
+ x87_fstp (&G->f, x86_deref (G->r_eax));
+ break;
+ case slang_asm_vec4_divide:
+ /* [vec4] | vec4 */
+ x86_mov (&G->f, G->r_eax, x86_make_disp (G->r_esp, 16));
+ x87_fld (&G->f, x86_deref (G->r_eax));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 4));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 8));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 12));
+ x87_fld (&G->f, x86_deref (G->r_esp));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 4));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 8));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 12));
+ x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 16));
+ x87_fdivp (&G->f, G->r_st4);
+ x87_fdivp (&G->f, G->r_st4);
+ x87_fdivp (&G->f, G->r_st4);
+ x87_fdivp (&G->f, G->r_st4);
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 12));
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 8));
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 4));
+ x87_fstp (&G->f, x86_deref (G->r_eax));
+ break;
+ case slang_asm_vec4_negate:
+ /* [vec4] */
+ x86_mov (&G->f, G->r_eax, x86_deref (G->r_esp));
+ x87_fld (&G->f, x86_deref (G->r_eax));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 4));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 8));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 12));
+ x87_fchs (&G->f);
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 12));
+ x87_fchs (&G->f);
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 8));
+ x87_fchs (&G->f);
+ x87_fstp (&G->f, x86_make_disp (G->r_eax, 4));
+ x87_fchs (&G->f);
+ x87_fstp (&G->f, x86_deref (G->r_eax));
+ break;
+ case slang_asm_vec4_dot:
+ /* [vec4] | vec4 */
+ x87_fld (&G->f, x86_deref (G->r_esp));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 4));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 8));
+ x87_fld (&G->f, x86_make_disp (G->r_esp, 12));
+ x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 16));
+ x86_mov (&G->f, G->r_eax, x86_deref (G->r_esp));
+ x87_fld (&G->f, x86_deref (G->r_eax));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 4));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 8));
+ x87_fld (&G->f, x86_make_disp (G->r_eax, 12));
+ x87_fmulp (&G->f, G->r_st4);
+ x87_fmulp (&G->f, G->r_st4);
+ x87_fmulp (&G->f, G->r_st4);
+ x87_fmulp (&G->f, G->r_st4);
+ x87_faddp (&G->f, G->r_st1);
+ x87_faddp (&G->f, G->r_st1);
+ x87_faddp (&G->f, G->r_st1);
+ x87_fstp (&G->f, x86_deref (G->r_eax));
+ break;
default:
assert (0);
}
GLubyte *j_body, *j_exit;
GLuint i;
+ /* Free the old code - if any.
+ */
+ if (mach->x86.compiled_func != NULL) {
+ _mesa_exec_free (mach->x86.compiled_func);
+ mach->x86.compiled_func = NULL;
+ }
+
/*
* We need as much as 1M because *all* assembly, including built-in library, is
* being translated to x86.
G.r_st1 = x86_make_reg (file_x87, 1);
G.r_st2 = x86_make_reg (file_x87, 2);
G.r_st3 = x86_make_reg (file_x87, 3);
+ G.r_st4 = x86_make_reg (file_x87, 4);
G.fixups = NULL;
G.fixup_count = 0;
G.labels = (GLubyte **) slang_alloc_malloc (file->count * sizeof (GLubyte *));
slang_alloc_free (G.labels);
/* install new code */
- if (mach->x86.compiled_func != NULL)
- _mesa_exec_free (mach->x86.compiled_func);
mach->x86.compiled_func = (GLvoid (*) (slang_machine *)) x86_get_func (&G.f);
return GL_TRUE;