@thi.ng/shader-ast-optimize 0.2.52 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -1
- package/contant-folding.js +27 -7
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-05-
|
|
3
|
+
- **Last updated**: 2023-05-24T14:26:03Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,13 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [0.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-optimize@0.3.0) (2023-05-24)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- update constant folding ([1bd5fef](https://github.com/thi-ng/umbrella/commit/1bd5fef))
|
|
17
|
+
- add simplifications for 0/1 cases
|
|
18
|
+
|
|
12
19
|
## [0.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-optimize@0.2.0) (2021-11-17)
|
|
13
20
|
|
|
14
21
|
#### 🚀 Features
|
package/contant-folding.js
CHANGED
|
@@ -5,7 +5,7 @@ import { clamp } from "@thi.ng/math/interval";
|
|
|
5
5
|
import { mix } from "@thi.ng/math/mix";
|
|
6
6
|
import { fract, mod } from "@thi.ng/math/prec";
|
|
7
7
|
import { isFloat, isInt, isLitNumericConst, isLitVecConst, isUint, } from "@thi.ng/shader-ast/ast/checks";
|
|
8
|
-
import { float, int, lit, uint } from "@thi.ng/shader-ast/ast/lit";
|
|
8
|
+
import { FLOAT0, float, int, lit, uint } from "@thi.ng/shader-ast/ast/lit";
|
|
9
9
|
import { allChildren, walk } from "@thi.ng/shader-ast/ast/scope";
|
|
10
10
|
import { LOGGER } from "@thi.ng/shader-ast/logger";
|
|
11
11
|
/**
|
|
@@ -84,13 +84,33 @@ export const foldNode = defmulti((t) => t.tag, {}, {
|
|
|
84
84
|
},
|
|
85
85
|
op2: (node) => {
|
|
86
86
|
const $node = node;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
const op = $node.op;
|
|
88
|
+
const l = $node.l;
|
|
89
|
+
const r = $node.r;
|
|
90
|
+
const isNumL = isLitNumericConst(l);
|
|
91
|
+
const isNumR = isLitNumericConst(r);
|
|
92
|
+
if (isNumL && isNumR) {
|
|
93
|
+
let res = maybeFoldMath(op, l.val, r.val);
|
|
94
|
+
if (res !== undefined)
|
|
92
95
|
return replaceNumericNode(node, res);
|
|
93
|
-
|
|
96
|
+
}
|
|
97
|
+
else if (op === "*") {
|
|
98
|
+
if ((isNumL && l.val === 0) || (isNumR && r.val === 0))
|
|
99
|
+
return replaceNode(node, FLOAT0);
|
|
100
|
+
if (isNumL && l.val === 1)
|
|
101
|
+
return replaceNode(node, r);
|
|
102
|
+
if (isNumR && r.val === 1)
|
|
103
|
+
return replaceNode(node, l);
|
|
104
|
+
}
|
|
105
|
+
else if (op === "/") {
|
|
106
|
+
if (isNumR && r.val === 1)
|
|
107
|
+
return replaceNode(node, l);
|
|
108
|
+
}
|
|
109
|
+
else if (op === "+" || op === "-") {
|
|
110
|
+
if (isNumL && l.val === 0)
|
|
111
|
+
return replaceNode(node, r);
|
|
112
|
+
if (isNumR && r.val === 0)
|
|
113
|
+
return replaceNode(node, l);
|
|
94
114
|
}
|
|
95
115
|
},
|
|
96
116
|
call_i: (node) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/shader-ast-optimize",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Shader AST code optimization passes/strategies",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"parent": "@thi.ng/shader-ast",
|
|
78
78
|
"year": 2019
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "26a171dff04a026e5466fc655b91c09e5279db8e\n"
|
|
81
81
|
}
|