title: Speed of cos() and sin() function in GLSL shaders?
body: <p>I'm interested in information about the speed of <code>sin()</code> and <code>cos()</code> in <em>Open GL Shader Language</em>.</p>
  
  <p>The <a href="http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.40.05.pdf" rel="noreferrer">GLSL Specification Document</a> indicates that:</p>
  
  <blockquote>
    <p>The built-in functions basically fall into three categories:</p>
    
    <ul>
    <li>...</li>
    <li>...</li>
    <li>They represent an operation graphics hardware is likely to accelerate at some point. The trigonometry functions fall into this
    category.</li>
    </ul>
  </blockquote>
  
  <p><strong>EDIT:</strong></p>
  
  <p>As has been pointed out, counting clock cycles of individual operations like <code>sin()</code> and <code>cos()</code> doesn't really tell the whole performance story.</p>
  
  <p>So to clarify my question, what I'm really interested in is whether it's worthwhile to optimize away <code>sin()</code> and <code>cos()</code> calls for common cases.</p>
  
  <p>For example, in my application it'll be very common for the argument to be <code>0</code>. So does something like this make sense:</p>
  
  <pre><code>float sina, cosa;
  
  if ( rotation == 0 )
  {
     sina = 0;
     cosa = 1;
  }
  else
  {
     sina = sin( rotation );
     cosa = cos( rotation );
  }
  </code></pre>
  
  <p>Or will the <code>GLSL</code> compiler or the <code>sin()</code> and <code>cos()</code> implementations take care of optimizations like that for me?</p>