X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=intrin.c;h=9ef02077b692eba828741cc7babefad9f928fffd;hb=9d89a059aa6d2a03d3a08de4db295e08e45458d9;hp=f3ae818caac0fee0a9441d6a9f6bdf8e81ef7b5c;hpb=072bff44e6d574f5f32657875adcbe48fc27cb5b;p=xonotic%2Fgmqcc.git diff --git a/intrin.c b/intrin.c index f3ae818..9ef0207 100644 --- a/intrin.c +++ b/intrin.c @@ -1,37 +1,6 @@ -/* - * Copyright (C) 2012, 2013 - * 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 #include "parser.h" -/* - * Provides all the "intrinsics" / "builtins" for GMQCC. These can do - * a few things, they can provide fall back implementations for math - * functions if the definitions don't exist for some given engine. Or - * then can determine definitions for existing builtins, and simply - * wrap back to them instead. This is like a "portable" intrface that - * is entered when -fintrin is used (causing all existing builtins to - * be ignored by the compiler and instead interface through here. - */ #define intrin_ctx(I) parser_ctx((I)->parser) static GMQCC_INLINE ast_function *intrin_value(intrin_t *intrin, ast_value **out, const char *name, qcint_t vtype) { @@ -422,7 +391,7 @@ static ast_expression *intrin_atanh(intrin_t *intrin) { (ast_expression*)ast_binary_new( intrin_ctx(intrin), INSTR_MUL_F, - (ast_expression*)fold_constgen_float(intrin->fold, 0.5), + (ast_expression*)fold_constgen_float(intrin->fold, 0.5, false), (ast_expression*)calllog ) ); @@ -496,7 +465,7 @@ static ast_expression *intrin_exp(intrin_t *intrin) { intrin_ctx(intrin), INSTR_LT, (ast_expression*)i, - (ast_expression*)fold_constgen_float(intrin->fold, 200.0f) + (ast_expression*)fold_constgen_float(intrin->fold, 200.0f, false) ), false, NULL, @@ -1027,7 +996,7 @@ static ast_expression *intrin_pow(intrin_t *intrin) { intrin_ctx(intrin), INSTR_GT, (ast_expression*)callfabs, - (ast_expression*)fold_constgen_float(intrin->fold, QC_POW_EPSILON) + (ast_expression*)fold_constgen_float(intrin->fold, QC_POW_EPSILON, false) ), /* pre not */ false, @@ -1911,7 +1880,7 @@ static ast_expression *intrin_log_variant(intrin_t *intrin, const char *name, fl vec_push(value->expression.params, arg1); vec_push(callln->params, (ast_expression*)arg1); - vec_push(callln->params, (ast_expression*)fold_constgen_float(intrin->fold, base)); + vec_push(callln->params, (ast_expression*)fold_constgen_float(intrin->fold, base, false)); vec_push(body->exprs, (ast_expression*)ast_return_new( @@ -1940,28 +1909,41 @@ static ast_expression *intrin_logb(intrin_t *intrin) { } static ast_expression *intrin_shift_variant(intrin_t *intrin, const char *name, size_t instr) { - ast_value *value = NULL; - ast_call *callpow = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "pow", name)); - ast_value *a = ast_value_new(intrin_ctx(intrin), "a", TYPE_FLOAT); - ast_value *b = ast_value_new(intrin_ctx(intrin), "b", TYPE_FLOAT); - ast_block *body = ast_block_new(intrin_ctx(intrin)); - ast_function *func = intrin_value(intrin, &value, name, TYPE_FLOAT); + /* + * float [shift] (float a, float b) { + * return floor(a [instr] pow(2, b)); + */ + ast_value *value = NULL; + ast_call *callpow = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "pow", name)); + ast_call *callfloor = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "floor", name)); + ast_value *a = ast_value_new(intrin_ctx(intrin), "a", TYPE_FLOAT); + ast_value *b = ast_value_new(intrin_ctx(intrin), "b", TYPE_FLOAT); + ast_block *body = ast_block_new(intrin_ctx(intrin)); + ast_function *func = intrin_value(intrin, &value, name, TYPE_FLOAT); vec_push(value->expression.params, a); vec_push(value->expression.params, b); + /* = pow(2, b) */ vec_push(callpow->params, (ast_expression*)intrin->fold->imm_float[3]); vec_push(callpow->params, (ast_expression*)b); + /* = floor(a [instr] ) */ + vec_push( + callfloor->params, + (ast_expression*)ast_binary_new( + intrin_ctx(intrin), + instr, + (ast_expression*)a, + (ast_expression*)callpow + ) + ); + + /* return */ vec_push(body->exprs, (ast_expression*)ast_return_new( intrin_ctx(intrin), - (ast_expression*)ast_binary_new( - intrin_ctx(intrin), - instr, - (ast_expression*)a, - (ast_expression*)callpow - ) + (ast_expression*)callfloor ) );