<div dir="ltr">On 22 August 2013 16:08, Matt Turner <span dir="ltr"><<a href="mailto:mattst88@gmail.com" target="_blank">mattst88@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
src/glsl/builtins/ir/<a href="http://frexp.ir" target="_blank">frexp.ir</a> | 25 +++++++++++++++++++++++++<br>
src/glsl/builtins/ir/<a href="http://ldexp.ir" target="_blank">ldexp.ir</a> | 25 +++++++++++++++++++++++++<br>
src/glsl/builtins/profiles/ARB_gpu_shader5.glsl | 10 ++++++++++<br>
3 files changed, 60 insertions(+)<br>
create mode 100644 src/glsl/builtins/ir/<a href="http://frexp.ir" target="_blank">frexp.ir</a><br>
create mode 100644 src/glsl/builtins/ir/<a href="http://ldexp.ir" target="_blank">ldexp.ir</a><br>
<br>
diff --git a/src/glsl/builtins/ir/<a href="http://frexp.ir" target="_blank">frexp.ir</a> b/src/glsl/builtins/ir/<a href="http://frexp.ir" target="_blank">frexp.ir</a><br>
new file mode 100644<br>
index 0000000..a514994<br>
--- /dev/null<br>
+++ b/src/glsl/builtins/ir/<a href="http://frexp.ir" target="_blank">frexp.ir</a><br>
@@ -0,0 +1,25 @@<br>
+((function frexp<br>
+ (signature float<br>
+ (parameters<br>
+ (declare (in) float x)<br>
+ (declare (out) int exp))<br>
+ ((return (expression float frexp (var_ref x) (var_ref exp)))))<br></blockquote><div><br></div><div>Having an ir_expression that writes to one of its parameters is going to break assumptions in a lot of our optimization passes. For example, if opt_tree_grafting encounters this code:<br>
<br></div><div>uniform float u;<br>void main()<br>{<br></div><div> int exp;<br></div><div> float f = frexp(u, out exp);<br></div><div> float g = float(exp)/256.0;<br></div><div> float h = float(exp) + 1.0;<br></div><div>
gl_FragColor = vec4(f, g, h, g + h);<br>}<br></div><div><br>it may try to optimize it to this:<br>
<br><div>uniform float u;<br>void main()<br>{<br></div><div> int exp;<br></div> float g = float(exp)/256.0;<br><div><div> float h = float(exp) + 1.0;<br></div> gl_FragColor = vec4(frexp(u, out exp), g, h, g + h);<br>
}<br></div><br></div>I think what we need to do is either:<br><br></div><div class="gmail_quote">1. Punt on the frexp_to_arith lowering pass for now, and instead just put the lowered code right here, or<br><br>2. In patch 7, replace ir_binop_frexp with two unary ops, one that computes the mantissa (return value of frexp()), and one that computes the integer exponent. Then this code will be effectively:<br>
<br></div><div class="gmail_quote">float frexp(float x, out int exp)<br>{<br></div><div class="gmail_quote"> exp = ir_unop_frexp_mantissa(x);<br></div><div class="gmail_quote"> return ir_unop_frexp_exponent(x);<br>}<br>
</div><div class="gmail_quote"><br></div><div class="gmail_quote"> I'm leaning toward option 1, because I suspect it will generate more efficient code (option 2 is likely to cause the if test in frexp_to_arith to be duplicated).<br>
</div><div class="gmail_quote">
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ (signature vec2<br>
+ (parameters<br>
+ (declare (in) vec2 x)<br>
+ (declare (out) ivec2 exp))<br>
+ ((return (expression vec2 frexp (var_ref x) (var_ref exp)))))<br>
+<br>
+ (signature vec3<br>
+ (parameters<br>
+ (declare (in) vec3 x)<br>
+ (declare (out) ivec3 exp))<br>
+ ((return (expression vec3 frexp (var_ref x) (var_ref exp)))))<br>
+<br>
+ (signature vec4<br>
+ (parameters<br>
+ (declare (in) vec4 x)<br>
+ (declare (out) ivec4 exp))<br>
+ ((return (expression vec4 frexp (var_ref x) (var_ref exp)))))<br>
+))<br>
diff --git a/src/glsl/builtins/ir/<a href="http://ldexp.ir" target="_blank">ldexp.ir</a> b/src/glsl/builtins/ir/<a href="http://ldexp.ir" target="_blank">ldexp.ir</a><br>
new file mode 100644<br>
index 0000000..dd25f5a<br>
--- /dev/null<br>
+++ b/src/glsl/builtins/ir/<a href="http://ldexp.ir" target="_blank">ldexp.ir</a><br>
@@ -0,0 +1,25 @@<br>
+((function ldexp<br>
+ (signature float<br>
+ (parameters<br>
+ (declare (in) float x)<br>
+ (declare (in) int exp))<br>
+ ((return (expression float ldexp (var_ref x) (var_ref exp)))))<br></blockquote><div><br></div><div>Note: ldexp is fine as a binop, since both its parameters are inputs.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+ (signature vec2<br>
+ (parameters<br>
+ (declare (in) vec2 x)<br>
+ (declare (in) ivec2 exp))<br>
+ ((return (expression vec2 ldexp (var_ref x) (var_ref exp)))))<br>
+<br>
+ (signature vec3<br>
+ (parameters<br>
+ (declare (in) vec3 x)<br>
+ (declare (in) ivec3 exp))<br>
+ ((return (expression vec3 ldexp (var_ref x) (var_ref exp)))))<br>
+<br>
+ (signature vec4<br>
+ (parameters<br>
+ (declare (in) vec4 x)<br>
+ (declare (in) ivec4 exp))<br>
+ ((return (expression vec4 ldexp (var_ref x) (var_ref exp)))))<br>
+))<br>
diff --git a/src/glsl/builtins/profiles/ARB_gpu_shader5.glsl b/src/glsl/builtins/profiles/ARB_gpu_shader5.glsl<br>
index 3f76283..36fc0de 100644<br>
--- a/src/glsl/builtins/profiles/ARB_gpu_shader5.glsl<br>
+++ b/src/glsl/builtins/profiles/ARB_gpu_shader5.glsl<br>
@@ -59,3 +59,13 @@ float fma(float a, float b, float c);<br>
vec2 fma(vec2 a, vec2 b, vec2 c);<br>
vec3 fma(vec3 a, vec3 b, vec3 c);<br>
vec4 fma(vec4 a, vec4 b, vec4 c);<br>
+<br>
+float frexp(float x, out int exp);<br>
+vec2 frexp(vec2 x, out ivec2 exp);<br>
+vec3 frexp(vec3 x, out ivec3 exp);<br>
+vec4 frexp(vec4 x, out ivec4 exp);<br>
+<br>
+float ldexp(float x, int exp);<br>
+vec2 ldexp(vec2 x, ivec2 exp);<br>
+vec3 ldexp(vec3 x, ivec3 exp);<br>
+vec4 ldexp(vec4 x, ivec4 exp);<br>
<span><font color="#888888">--<br>
1.8.3.2<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>