[LLVMdev] complex numbers with LLVM

Richard legalize at xmission.com
Tue Dec 21 09:22:41 PST 2010


Hi,

I'm working on a project to generate native code for a domain specific
langauge where the user defines functions in the complex plane.  This
implies that I need to support complex numbers as a datatype with
LLVM.  Its fairly straightforward to create a struct of two floats (or
doubles, etc.) and do the simple operations like add, subtract,
multiply, divide, etc.

However, things get stickier when we get to the trig functions.  At
that point, I'd rather defer to the trig functions implemented in C++,
possibly taking them from boost's TR1 support instead of my compiler's
TR1 support.  At any rate, these functions aren't like the cos
function in the math library because they are possibly template
expansions from a header file.

This leaves me with two basic types of questions:

1. Is there a "best" representation for complex numbers in LLVM?
   Is my simple "struct of two floats" idea sufficient?
   Is there a way to maintain binary compatability with
   std::complex<float> or std::complex<double> so that those types can
   be used directly when calling LLVM generated native code?

2. What's the best way to expose the C++ complex trig, etc., functions?
   Is there a way I can use LLVM IR to write the type signature of
   these functions?
   Do I need to provide my own wrapper matching the representation
   used in 1. above?

Thanks for your time.
-- 
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
 <http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/>

      Legalize Adulthood! <http://legalizeadulthood.wordpress.com>



More information about the llvm-dev mailing list