Add ir_dereference constructor for structure field dereferences
[mesa.git] / builtin_function.cpp
index 684a10c8893e13feda1df68e25396fbf24a372c0..ff731c21625db2919190ba5f0cffb5e78df812e1 100644 (file)
@@ -34,13 +34,12 @@ generate_unop(exec_list *instructions,
              const glsl_type *type,
              enum ir_expression_operation op)
 {
-   ir_dereference *const retval = new ir_dereference(declarations[16]);
    ir_dereference *const arg = new ir_dereference(declarations[0]);
    ir_rvalue *result;
 
    result = new ir_expression(op, type, arg, NULL);
 
-   ir_instruction *inst = new ir_assignment(retval, result, NULL);
+   ir_instruction *inst = new ir_return(result);
    instructions->push_tail(inst);
 }
 
@@ -50,14 +49,13 @@ generate_binop(exec_list *instructions,
               const glsl_type *type,
               enum ir_expression_operation op)
 {
-   ir_dereference *const retval = new ir_dereference(declarations[16]);
    ir_dereference *const arg1 = new ir_dereference(declarations[0]);
    ir_dereference *const arg2 = new ir_dereference(declarations[1]);
    ir_rvalue *result;
 
    result = new ir_expression(op, type, arg1, arg2);
 
-   ir_instruction *inst = new ir_assignment(retval, result, NULL);
+   ir_instruction *inst = new ir_return(result);
    instructions->push_tail(inst);
 }
 
@@ -66,7 +64,6 @@ generate_radians(exec_list *instructions,
                 ir_variable **declarations,
                 const glsl_type *type)
 {
-   ir_dereference *const retval = new ir_dereference(declarations[16]);
    ir_dereference *const arg = new ir_dereference(declarations[0]);
    ir_rvalue *result;
 
@@ -74,7 +71,7 @@ generate_radians(exec_list *instructions,
                              arg,
                              new ir_constant((float)(M_PI / 180.0)));
 
-   ir_instruction *inst = new ir_assignment(retval, result, NULL);
+   ir_instruction *inst = new ir_return(result);
    instructions->push_tail(inst);
 }
 
@@ -83,7 +80,6 @@ generate_degrees(exec_list *instructions,
                 ir_variable **declarations,
                 const glsl_type *type)
 {
-   ir_dereference *const retval = new ir_dereference(declarations[16]);
    ir_dereference *const arg = new ir_dereference(declarations[0]);
    ir_rvalue *result;
 
@@ -91,7 +87,7 @@ generate_degrees(exec_list *instructions,
                              arg,
                              new ir_constant((float)(180.0 / M_PI)));
 
-   ir_instruction *inst = new ir_assignment(retval, result, NULL);
+   ir_instruction *inst = new ir_return(result);
    instructions->push_tail(inst);
 }
 
@@ -191,6 +187,61 @@ generate_max(exec_list *instructions,
    generate_binop(instructions, declarations, type, ir_binop_max);
 }
 
+static void
+generate_clamp(exec_list *instructions,
+              ir_variable **declarations,
+              const glsl_type *type)
+{
+   ir_dereference *const x = new ir_dereference(declarations[0]);
+   ir_dereference *const minval = new ir_dereference(declarations[1]);
+   ir_dereference *const maxval = new ir_dereference(declarations[2]);
+   ir_rvalue *result;
+
+   result = new ir_expression(ir_binop_min, type, x, maxval);
+   result = new ir_expression(ir_binop_max, type, result, minval);
+
+   ir_instruction *inst = new ir_return(result);
+   instructions->push_tail(inst);
+}
+
+static void
+generate_mix_vec(exec_list *instructions,
+                ir_variable **declarations,
+                const glsl_type *type)
+{
+   ir_dereference *const x = new ir_dereference(declarations[0]);
+   ir_dereference *const y = new ir_dereference(declarations[1]);
+   ir_dereference *const a = new ir_dereference(declarations[2]);
+   ir_rvalue *result, *temp;
+
+   temp = new ir_expression(ir_binop_sub, type, new ir_constant(1.0f), a);
+   result = new ir_expression(ir_binop_mul, type, x, temp);
+
+   temp = new ir_expression(ir_binop_mul, type, y, a);
+   result = new ir_expression(ir_binop_add, type, result, temp);
+
+   ir_instruction *inst = new ir_return(result);
+   instructions->push_tail(inst);
+}
+
+
+static void
+generate_normalize(exec_list *instructions,
+                  ir_variable **declarations,
+                  const glsl_type *type)
+{
+   ir_dereference *const arg = new ir_dereference(declarations[0]);
+   ir_rvalue *temp;
+   ir_rvalue *result;
+
+   temp = new ir_expression(ir_binop_dot, glsl_type::float_type, arg, arg);
+   temp = new ir_expression(ir_unop_rsq, glsl_type::float_type, temp, NULL);
+   result = new ir_expression(ir_binop_mul, type, arg, temp);
+
+   ir_instruction *inst = new ir_return(result);
+   instructions->push_tail(inst);
+}
+
 
 static void
 generate_pow(exec_list *instructions,
@@ -202,8 +253,6 @@ generate_pow(exec_list *instructions,
 
 void
 generate_function_instance(ir_function *f,
-                          const char *name,
-                          exec_list *instructions,
                           int n_args,
                           void (*generate)(exec_list *instructions,
                                            ir_variable **declarations,
@@ -211,39 +260,29 @@ generate_function_instance(ir_function *f,
                           const glsl_type *ret_type,
                           const glsl_type *type)
 {
-   ir_variable *declarations[17];
+   ir_variable *declarations[16];
 
-   ir_function_signature *const sig = new ir_function_signature(type);
+   ir_function_signature *const sig = new ir_function_signature(ret_type);
    f->add_signature(sig);
 
-   ir_label *const label = new ir_label(name);
-   instructions->push_tail(label);
-   sig->definition = label;
    static const char *arg_names[] = {
       "arg0",
-      "arg1"
+      "arg1",
+      "arg2"
    };
    int i;
 
    for (i = 0; i < n_args; i++) {
       ir_variable *var = new ir_variable(type, arg_names[i]);
 
-      var = new ir_variable(type, arg_names[i]);
       var->mode = ir_var_in;
       sig->parameters.push_tail(var);
 
-      var = new ir_variable(type, arg_names[i]);
-      var->mode = ir_var_in;
-      instructions->push_tail(var);
       declarations[i] = var;
    }
 
-   ir_variable *retval = new ir_variable(ret_type, "__retval");
-   instructions->push_tail(retval);
-
-   declarations[16] = retval;
-
-   generate(instructions, declarations, type);
+   generate(&sig->body, declarations, type);
+   sig->is_defined = true;
 }
 
 void
@@ -255,22 +294,159 @@ make_gentype_function(glsl_symbol_table *symtab, exec_list *instructions,
                                       const glsl_type *type))
 {
    ir_function *const f = new ir_function(name);
-   const glsl_type *float_type = glsl_type::float_type;
-   const glsl_type *vec2_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 2, 1);
-   const glsl_type *vec3_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 3, 1);
-   const glsl_type *vec4_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
 
    bool added = symtab->add_function(name, f);
    assert(added);
 
-   generate_function_instance(f, name, instructions, n_args, generate,
-                             float_type, float_type);
-   generate_function_instance(f, name, instructions, n_args, generate,
-                             vec2_type, vec2_type);
-   generate_function_instance(f, name, instructions, n_args, generate,
-                             vec3_type, vec3_type);
-   generate_function_instance(f, name, instructions, n_args, generate,
-                             vec4_type, vec4_type);
+   instructions->push_tail(f);
+
+   generate_function_instance(f, n_args, generate,
+                             glsl_type::float_type, glsl_type::float_type);
+   generate_function_instance(f, n_args, generate,
+                             glsl_type::vec2_type, glsl_type::vec2_type);
+   generate_function_instance(f, n_args, generate,
+                             glsl_type::vec3_type, glsl_type::vec3_type);
+   generate_function_instance(f, n_args, generate,
+                             glsl_type::vec4_type, glsl_type::vec4_type);
+}
+
+static void
+generate_vec_compare(exec_list *instructions,
+                    ir_variable **declarations,
+                    const glsl_type *type,
+                    enum ir_expression_operation op)
+{
+   ir_dereference *const x = new ir_dereference(declarations[0]);
+   ir_dereference *const y = new ir_dereference(declarations[1]);
+   ir_variable *temp;
+   const glsl_type *return_type;
+   int i;
+
+   return_type = glsl_type::get_instance(GLSL_TYPE_BOOL,
+                                        type->vector_elements, 1);
+   temp = new ir_variable(return_type, "temp");
+   instructions->push_tail(temp);
+
+   for (i = 0; i < type->vector_elements; i++) {
+      ir_assignment *assign;
+      ir_expression *compare;
+
+      compare = new ir_expression(op,
+                                 glsl_type::get_instance(type->base_type,
+                                                         1, 1),
+                                 new ir_swizzle(x, i, 0, 0, 0, 1),
+                                 new ir_swizzle(y, i, 0, 0, 0, 1));
+      assign = new ir_assignment(new ir_swizzle(new ir_dereference(temp),
+                                               i, 0, 0, 0, 1),
+                                compare, NULL);
+      instructions->push_tail(assign);
+   }
+   ir_instruction *inst = new ir_return(new ir_dereference(temp));
+   instructions->push_tail(inst);
+}
+
+static void
+generate_lessThan(exec_list *instructions,
+                 ir_variable **declarations,
+                 const glsl_type *type)
+{
+   generate_vec_compare(instructions, declarations, type, ir_binop_less);
+}
+
+static void
+generate_lessThanEqual(exec_list *instructions,
+                      ir_variable **declarations,
+                      const glsl_type *type)
+{
+   generate_vec_compare(instructions, declarations, type, ir_binop_lequal);
+}
+
+static void
+generate_greaterThan(exec_list *instructions,
+                    ir_variable **declarations,
+                    const glsl_type *type)
+{
+   generate_vec_compare(instructions, declarations, type, ir_binop_greater);
+}
+
+static void
+generate_greaterThanEqual(exec_list *instructions,
+                         ir_variable **declarations,
+                         const glsl_type *type)
+{
+   generate_vec_compare(instructions, declarations, type, ir_binop_gequal);
+}
+
+static void
+generate_equal(exec_list *instructions,
+              ir_variable **declarations,
+              const glsl_type *type)
+{
+   generate_vec_compare(instructions, declarations, type, ir_binop_equal);
+}
+
+static void
+generate_notEqual(exec_list *instructions,
+                 ir_variable **declarations,
+                 const glsl_type *type)
+{
+   generate_vec_compare(instructions, declarations, type, ir_binop_nequal);
+}
+
+static void
+generate_vec_compare_function(glsl_symbol_table *symtab,
+                             exec_list *instructions,
+                             const char *name,
+                             void (*generate)(exec_list *instructions,
+                                              ir_variable **declarations,
+                                              const glsl_type *type),
+                             bool do_bool)
+{
+   ir_function *const f = new ir_function(name);
+   const glsl_type *ivec2_type = glsl_type::get_instance(GLSL_TYPE_INT, 2, 1);
+   const glsl_type *ivec3_type = glsl_type::get_instance(GLSL_TYPE_INT, 3, 1);
+   const glsl_type *ivec4_type = glsl_type::get_instance(GLSL_TYPE_INT, 4, 1);
+   const glsl_type *uvec2_type = glsl_type::get_instance(GLSL_TYPE_UINT, 2, 1);
+   const glsl_type *uvec3_type = glsl_type::get_instance(GLSL_TYPE_UINT, 3, 1);
+   const glsl_type *uvec4_type = glsl_type::get_instance(GLSL_TYPE_UINT, 4, 1);
+   const glsl_type *bvec2_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 2, 1);
+   const glsl_type *bvec3_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 3, 1);
+   const glsl_type *bvec4_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1);
+
+   bool added = symtab->add_function(name, f);
+   assert(added);
+
+   instructions->push_tail(f);
+
+   generate_function_instance(f, 2, generate,
+                             bvec2_type, glsl_type::vec2_type);
+   generate_function_instance(f, 2, generate,
+                             bvec3_type, glsl_type::vec3_type);
+   generate_function_instance(f, 2, generate,
+                             bvec4_type, glsl_type::vec4_type);
+
+   generate_function_instance(f, 2, generate,
+                             bvec2_type, ivec2_type);
+   generate_function_instance(f, 2, generate,
+                             bvec3_type, ivec3_type);
+   generate_function_instance(f, 2, generate,
+                             bvec4_type, ivec4_type);
+
+   generate_function_instance(f, 2, generate,
+                             bvec2_type, uvec2_type);
+   generate_function_instance(f, 2, generate,
+                             bvec3_type, uvec3_type);
+   generate_function_instance(f, 2, generate,
+                             bvec4_type, uvec4_type);
+
+   if (do_bool) {
+      generate_function_instance(f, 2, generate,
+                                bvec2_type, bvec2_type);
+      generate_function_instance(f, 2, generate,
+                                bvec3_type, bvec3_type);
+      generate_function_instance(f, 2, generate,
+                                bvec4_type, bvec4_type);
+   }
 }
 
 static void
@@ -278,7 +454,6 @@ generate_length(exec_list *instructions,
                ir_variable **declarations,
                const glsl_type *type)
 {
-   ir_dereference *const retval = new ir_dereference(declarations[16]);
    ir_dereference *const arg = new ir_dereference(declarations[0]);
    ir_rvalue *result, *temp;
 
@@ -289,7 +464,7 @@ generate_length(exec_list *instructions,
    temp = new ir_expression(ir_binop_dot, glsl_type::float_type, arg, arg);
    result = new ir_expression(ir_unop_sqrt, glsl_type::float_type, temp, NULL);
 
-   ir_instruction *inst = new ir_assignment(retval, result, NULL);
+   ir_instruction *inst = new ir_return(result);
    instructions->push_tail(inst);
 }
 
@@ -298,22 +473,20 @@ generate_length_functions(glsl_symbol_table *symtab, exec_list *instructions)
 {
    const char *name = "length";
    ir_function *const f = new ir_function(name);
-   const glsl_type *float_type = glsl_type::float_type;
-   const glsl_type *vec2_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 2, 1);
-   const glsl_type *vec3_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 3, 1);
-   const glsl_type *vec4_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
 
    bool added = symtab->add_function(name, f);
    assert(added);
 
-   generate_function_instance(f, name, instructions, 1, generate_length,
-                             float_type, float_type);
-   generate_function_instance(f, name, instructions, 1, generate_length,
-                             float_type, vec2_type);
-   generate_function_instance(f, name, instructions, 1, generate_length,
-                             float_type, vec3_type);
-   generate_function_instance(f, name, instructions, 1, generate_length,
-                             float_type, vec4_type);
+   instructions->push_tail(f);
+
+   generate_function_instance(f, 1, generate_length,
+                             glsl_type::float_type, glsl_type::float_type);
+   generate_function_instance(f, 1, generate_length,
+                             glsl_type::float_type, glsl_type::vec2_type);
+   generate_function_instance(f, 1, generate_length,
+                             glsl_type::float_type, glsl_type::vec3_type);
+   generate_function_instance(f, 1, generate_length,
+                             glsl_type::float_type, glsl_type::vec4_type);
 }
 
 static void
@@ -321,15 +494,15 @@ generate_dot(exec_list *instructions,
                ir_variable **declarations,
                const glsl_type *type)
 {
-   ir_dereference *const retval = new ir_dereference(declarations[16]);
-   ir_dereference *const arg = new ir_dereference(declarations[0]);
+   ir_dereference *const arg0 = new ir_dereference(declarations[0]);
+   ir_dereference *const arg1 = new ir_dereference(declarations[1]);
    ir_rvalue *result;
 
    (void)type;
 
-   result = new ir_expression(ir_binop_dot, glsl_type::float_type, arg, arg);
+   result = new ir_expression(ir_binop_dot, glsl_type::float_type, arg0, arg1);
 
-   ir_instruction *inst = new ir_assignment(retval, result, NULL);
+   ir_instruction *inst = new ir_return(result);
    instructions->push_tail(inst);
 }
 
@@ -338,22 +511,226 @@ generate_dot_functions(glsl_symbol_table *symtab, exec_list *instructions)
 {
    const char *name = "dot";
    ir_function *const f = new ir_function(name);
-   const glsl_type *float_type = glsl_type::float_type;
-   const glsl_type *vec2_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 2, 1);
-   const glsl_type *vec3_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 3, 1);
-   const glsl_type *vec4_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
 
    bool added = symtab->add_function(name, f);
    assert(added);
 
-   generate_function_instance(f, name, instructions, 1, generate_dot,
-                             float_type, float_type);
-   generate_function_instance(f, name, instructions, 1, generate_dot,
-                             float_type, vec2_type);
-   generate_function_instance(f, name, instructions, 1, generate_dot,
-                             float_type, vec3_type);
-   generate_function_instance(f, name, instructions, 1, generate_dot,
-                             float_type, vec4_type);
+   instructions->push_tail(f);
+
+   generate_function_instance(f, 2, generate_dot,
+                             glsl_type::float_type, glsl_type::float_type);
+   generate_function_instance(f, 2, generate_dot,
+                             glsl_type::float_type, glsl_type::vec2_type);
+   generate_function_instance(f, 2, generate_dot,
+                             glsl_type::float_type, glsl_type::vec3_type);
+   generate_function_instance(f, 2, generate_dot,
+                             glsl_type::float_type, glsl_type::vec4_type);
+}
+
+static void
+generate_any_bvec2(exec_list *instructions,
+                  ir_variable **declarations,
+                  const glsl_type *type)
+{
+   ir_dereference *const arg0 = new ir_dereference(declarations[0]);
+   ir_rvalue *result;
+
+   (void)type;
+
+   result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
+                             new ir_swizzle(arg0, 0, 0, 0, 0, 1),
+                             new ir_swizzle(arg0, 1, 0, 0, 0, 1));
+
+   ir_instruction *inst = new ir_return(result);
+   instructions->push_tail(inst);
+}
+
+static void
+generate_any_bvec3(exec_list *instructions,
+                  ir_variable **declarations,
+                  const glsl_type *type)
+{
+   ir_dereference *const arg0 = new ir_dereference(declarations[0]);
+   ir_rvalue *result;
+
+   (void)type;
+
+   result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
+                             new ir_swizzle(arg0, 0, 0, 0, 0, 1),
+                             new ir_swizzle(arg0, 1, 0, 0, 0, 1));
+   result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
+                             result,
+                             new ir_swizzle(arg0, 2, 0, 0, 0, 1));
+
+   ir_instruction *inst = new ir_return(result);
+   instructions->push_tail(inst);
+}
+
+static void
+generate_any_bvec4(exec_list *instructions,
+                  ir_variable **declarations,
+                  const glsl_type *type)
+{
+   ir_dereference *const arg0 = new ir_dereference(declarations[0]);
+   ir_rvalue *result;
+
+   (void)type;
+
+   result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
+                             new ir_swizzle(arg0, 0, 0, 0, 0, 1),
+                             new ir_swizzle(arg0, 1, 0, 0, 0, 1));
+   result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
+                             result,
+                             new ir_swizzle(arg0, 2, 0, 0, 0, 1));
+   result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
+                             result,
+                             new ir_swizzle(arg0, 3, 0, 0, 0, 1));
+
+   ir_instruction *inst = new ir_return(result);
+   instructions->push_tail(inst);
+}
+
+static void
+generate_all_bvec2(exec_list *instructions,
+                  ir_variable **declarations,
+                  const glsl_type *type)
+{
+   ir_dereference *const arg0 = new ir_dereference(declarations[0]);
+   ir_rvalue *result;
+
+   (void)type;
+
+   result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
+                             new ir_swizzle(arg0, 0, 0, 0, 0, 1),
+                             new ir_swizzle(arg0, 1, 0, 0, 0, 1));
+
+   ir_instruction *inst = new ir_return(result);
+   instructions->push_tail(inst);
+}
+
+static void
+generate_all_bvec3(exec_list *instructions,
+                  ir_variable **declarations,
+                  const glsl_type *type)
+{
+   ir_dereference *const arg0 = new ir_dereference(declarations[0]);
+   ir_rvalue *result;
+
+   (void)type;
+
+   result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
+                             new ir_swizzle(arg0, 0, 0, 0, 0, 1),
+                             new ir_swizzle(arg0, 1, 0, 0, 0, 1));
+   result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
+                             result,
+                             new ir_swizzle(arg0, 2, 0, 0, 0, 1));
+
+   ir_instruction *inst = new ir_return(result);
+   instructions->push_tail(inst);
+}
+
+static void
+generate_all_bvec4(exec_list *instructions,
+                  ir_variable **declarations,
+                  const glsl_type *type)
+{
+   ir_dereference *const arg0 = new ir_dereference(declarations[0]);
+   ir_rvalue *result;
+
+   (void)type;
+
+   result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
+                             new ir_swizzle(arg0, 0, 0, 0, 0, 1),
+                             new ir_swizzle(arg0, 1, 0, 0, 0, 1));
+   result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
+                             result,
+                             new ir_swizzle(arg0, 2, 0, 0, 0, 1));
+   result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
+                             result,
+                             new ir_swizzle(arg0, 3, 0, 0, 0, 1));
+
+   ir_instruction *inst = new ir_return(result);
+   instructions->push_tail(inst);
+}
+
+static void
+generate_not(exec_list *instructions,
+            ir_variable **declarations,
+            const glsl_type *type)
+{
+   ir_dereference *const arg0 = new ir_dereference(declarations[0]);
+   ir_rvalue *result;
+
+   result = new ir_expression(ir_unop_logic_not, type, arg0, NULL);
+
+   ir_instruction *inst = new ir_return(result);
+   instructions->push_tail(inst);
+}
+
+void
+generate_any_functions(glsl_symbol_table *symtab, exec_list *instructions)
+{
+   const char *name = "any";
+   ir_function *const f = new ir_function(name);
+   const glsl_type *bvec2_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 2, 1);
+   const glsl_type *bvec3_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 3, 1);
+   const glsl_type *bvec4_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1);
+
+   bool added = symtab->add_function(name, f);
+   assert(added);
+
+   instructions->push_tail(f);
+
+   generate_function_instance(f, 1, generate_any_bvec2,
+                             glsl_type::bool_type, bvec2_type);
+   generate_function_instance(f, 1, generate_any_bvec3,
+                             glsl_type::bool_type, bvec3_type);
+   generate_function_instance(f, 1, generate_any_bvec4,
+                             glsl_type::bool_type, bvec4_type);
+}
+
+void
+generate_all_functions(glsl_symbol_table *symtab, exec_list *instructions)
+{
+   const char *name = "all";
+   ir_function *const f = new ir_function(name);
+   const glsl_type *bvec2_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 2, 1);
+   const glsl_type *bvec3_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 3, 1);
+   const glsl_type *bvec4_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1);
+
+   bool added = symtab->add_function(name, f);
+   assert(added);
+
+   instructions->push_tail(f);
+
+   generate_function_instance(f, 1, generate_all_bvec2,
+                             glsl_type::bool_type, bvec2_type);
+   generate_function_instance(f, 1, generate_all_bvec3,
+                             glsl_type::bool_type, bvec3_type);
+   generate_function_instance(f, 1, generate_all_bvec4,
+                             glsl_type::bool_type, bvec4_type);
+}
+
+void
+generate_not_functions(glsl_symbol_table *symtab, exec_list *instructions)
+{
+   const char *name = "not";
+   ir_function *const f = new ir_function(name);
+   const glsl_type *bvec2_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 2, 1);
+   const glsl_type *bvec3_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 3, 1);
+   const glsl_type *bvec4_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1);
+
+   bool added = symtab->add_function(name, f);
+   assert(added);
+
+   instructions->push_tail(f);
+
+   generate_function_instance(f, 1, generate_not,
+                             bvec2_type, bvec2_type);
+   generate_function_instance(f, 1, generate_not,
+                             bvec3_type, bvec3_type);
+   generate_function_instance(f, 1, generate_not,
+                             bvec4_type, bvec4_type);
 }
 
 void
@@ -386,9 +763,9 @@ generate_110_functions(glsl_symbol_table *symtab, exec_list *instructions)
    /* FINISHME: min(x, float y) */
    make_gentype_function(symtab, instructions, "max", 2, generate_max);
    /* FINISHME: max(x, float y) */
+   make_gentype_function(symtab, instructions, "clamp", 3, generate_clamp);
    /* FINISHME: clamp() */
-   /* FINISHME: clamp() */
-   /* FINISHME: mix() */
+   make_gentype_function(symtab, instructions, "mix", 3, generate_mix_vec);
    /* FINISHME: mix() */
    /* FINISHME: step() */
    /* FINISHME: step() */
@@ -400,21 +777,31 @@ generate_110_functions(glsl_symbol_table *symtab, exec_list *instructions)
    /* FINISHME: distance() */
    generate_dot_functions(symtab, instructions);
    /* FINISHME: cross() */
+   make_gentype_function(symtab, instructions, "normalize", 1,
+                        generate_normalize);
    /* FINISHME: normalize() */
    /* FINISHME: ftransform() */
    /* FINISHME: faceforward() */
    /* FINISHME: reflect() */
    /* FINISHME: refract() */
    /* FINISHME: matrixCompMult() */
-   /* FINISHME: lessThan() */
-   /* FINISHME: lessThanEqual() */
-   /* FINISHME: greaterThan() */
-   /* FINISHME: greaterThanEqual() */
-   /* FINISHME: equal() */
-   /* FINISHME: notEqual() */
-   /* FINISHME: any() */
-   /* FINISHME: all() */
-   /* FINISHME: not() */
+   generate_vec_compare_function(symtab, instructions,
+                                "lessThan", generate_lessThan, false);
+   generate_vec_compare_function(symtab, instructions,
+                                "lessThanEqual", generate_lessThanEqual,
+                                false);
+   generate_vec_compare_function(symtab, instructions,
+                                "greaterThan", generate_greaterThan, false);
+   generate_vec_compare_function(symtab, instructions,
+                                "greaterThanEqual", generate_greaterThanEqual,
+                                false);
+   generate_vec_compare_function(symtab, instructions,
+                                "equal", generate_equal, false);
+   generate_vec_compare_function(symtab, instructions,
+                                "notEqual", generate_notEqual, false);
+   generate_any_functions(symtab, instructions);
+   generate_all_functions(symtab, instructions);
+   generate_not_functions(symtab, instructions);
    /* FINISHME: texture*() */
    /* FINISHME: shadow*() */
    /* FINISHME: dFd[xy]() */