]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - fold.c
More cleanup
[xonotic/gmqcc.git] / fold.c
diff --git a/fold.c b/fold.c
index 176d6b84516ad46b0fd410b463c7c18c2770857a..64b20d94e7662f7d1802293c39ebe670e2803da1 100644 (file)
--- a/fold.c
+++ b/fold.c
@@ -1,25 +1,3 @@
-/*
- * Copyright (C) 2012, 2013, 2014
- *     Dale Weiler
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
 #include <string.h>
 #include <math.h>
 
@@ -52,6 +30,7 @@ typedef union {
     sfloat_t  s;
 } sfloat_cast_t;
 
+/* Exception flags */
 typedef enum {
     SFLOAT_NOEXCEPT  = 0,
     SFLOAT_INVALID   = 1,
@@ -61,6 +40,7 @@ typedef enum {
     SFLOAT_INEXACT   = 32
 } sfloat_exceptionflags_t;
 
+/* Rounding modes */
 typedef enum {
     SFLOAT_ROUND_NEAREST_EVEN,
     SFLOAT_ROUND_DOWN,
@@ -68,6 +48,7 @@ typedef enum {
     SFLOAT_ROUND_TO_ZERO
 } sfloat_roundingmode_t;
 
+/* Underflow tininess-detection mode */
 typedef enum {
     SFLOAT_TAFTER,
     SFLOAT_TBEFORE
@@ -544,7 +525,7 @@ static GMQCC_INLINE void sfloat_init(sfloat_state_t *state) {
 
 /*
  * There is two stages to constant folding in GMQCC: there is the parse
- * stage constant folding, where, withhe help of the AST, operator
+ * stage constant folding, where, with the help of the AST, operator
  * usages can be constant folded. Then there is the constant folding
  * in the IR for things like eliding if statements, can occur.
  *
@@ -1097,29 +1078,9 @@ static bool fold_check_inexact_float(fold_t *fold, ast_value *a, ast_value *b) {
 }
 
 static GMQCC_INLINE ast_expression *fold_op_mul_vec(fold_t *fold, vec3_t vec, ast_value *sel, const char *set) {
-    /*
-     * vector-component constant folding works by matching the component sets
-     * to eliminate expensive operations on whole-vectors (3 components at runtime).
-     * to achive this effect in a clean manner this function generalizes the
-     * values through the use of a set paramater, which is used as an indexing method
-     * for creating the elided ast binary expression.
-     *
-     * Consider 'n 0 0' where y, and z need to be tested for 0, and x is
-     * used as the value in a binary operation generating an INSTR_MUL instruction,
-     * to acomplish the indexing of the correct component value we use set[0], set[1], set[2]
-     * as x, y, z, where the values of those operations return 'x', 'y', 'z'. Because
-     * of how ASCII works we can easily deliniate:
-     * vec.z is the same as set[2]-'x' for when set[2] is 'z', 'z'-'x' results in a
-     * literal value of 2, using this 2, we know that taking the address of vec->x (float)
-     * and indxing it with this literal will yeild the immediate address of that component
-     *
-     * Of course more work needs to be done to generate the correct index for the ast_member_new
-     * call, which is no problem: set[0]-'x' suffices that job.
-     */
     qcfloat_t x = (&vec.x)[set[0]-'x'];
     qcfloat_t y = (&vec.x)[set[1]-'x'];
     qcfloat_t z = (&vec.x)[set[2]-'x'];
-
     if (!y && !z) {
         ast_expression *out;
         ++opts_optimizationcount[OPTIM_VECTOR_COMPONENTS];
@@ -1497,8 +1458,8 @@ ast_expression *fold_op(fold_t *fold, const oper_info *info, ast_expression **op
 }
 
 /*
- * Constant folding for compiler intrinsics, simaler approach to operator
- * folding, primarly: individual functions for each intrinsics to fold,
+ * Constant folding for compiler intrinsics, similar approach to operator
+ * folding, primarily: individual functions for each intrinsics to fold,
  * and a generic selection function.
  */
 static GMQCC_INLINE ast_expression *fold_intrin_isfinite(fold_t *fold, ast_value *a) {