[haskell-llvm] fptoui et.al. for vectors

Henning Thielemann lemming at henning-thielemann.de
Sat Jul 24 13:57:03 EDT 2010


I like to propose another patch that generalizes conversions between
integers and floating point numbers to vectors. However the way, I did
it so far, is incompatible with the current version of the 'llvm'
package. Do you want it that way? This would require to bump version to
llvm-0.9 - if you follow the package versioning policy, at all. If not I
would have to give the generic functions new names like fptouiVector or
fptouiGeneric or put them in a separate module and call it like
Vector.fptoui. I made (NumberOfElements D1 a) a constraint of class
IsPrimitive a. This enforces consistency between NumberOfElements and
IsPrimitive instance, but of course this is also incompatible with
llvm-0.8.0.2. (If you decide to do incompatible changes, then also
consider replacing bitcast by the recently submitted bitcastUnify, since
the constraint (sa :==: sb) of bitcast is extremely unhandy in practical
use.)

$ darcs diff --unified
diff -rN -u old-llvm-0.8-merge/LLVM/Core/Instructions.hs
new-llvm-0.8-merge/LLVM/Core/Instructions.hs
--- old-llvm-0.8-merge/LLVM/Core/Instructions.hs        2010-07-24
19:24:08.000000000 +0200
+++ new-llvm-0.8-merge/LLVM/Core/Instructions.hs        2010-07-24
19:24:08.000000000 +0200
@@ -352,21 +352,20 @@
       => Value a -> CodeGenFunction r (Value b)
 fpext = convert FFI.buildFPExt

--- XXX The fp<->i conversion can handle vectors.
 -- | Convert a floating point value to an unsigned integer.
-fptoui :: (IsFloating a, IsInteger b, IsPrimitive a, IsPrimitive b) =>
Value a -> CodeGenFunction r (Value b)
+fptoui :: (IsFloating a, IsInteger b, NumberOfElements n a,
NumberOfElements n b) => Value a -> CodeGenFunction r (Value b)
 fptoui = convert FFI.buildFPToUI

 -- | Convert a floating point value to a signed integer.
-fptosi :: (IsFloating a, IsInteger b, IsPrimitive a, IsPrimitive b) =>
Value a -> CodeGenFunction r (Value b)
+fptosi :: (IsFloating a, IsInteger b, NumberOfElements n a,
NumberOfElements n b) => Value a -> CodeGenFunction r (Value b)
 fptosi = convert FFI.buildFPToSI

 -- | Convert an unsigned integer to a floating point value.
-uitofp :: (IsInteger a, IsFloating b, IsPrimitive a, IsPrimitive b) =>
Value a -> CodeGenFunction r (Value b)
+uitofp :: (IsInteger a, IsFloating b, NumberOfElements n a,
NumberOfElements n b) => Value a -> CodeGenFunction r (Value b)
 uitofp = convert FFI.buildUIToFP

 -- | Convert a signed integer to a floating point value.
-sitofp :: (IsInteger a, IsFloating b, IsPrimitive a, IsPrimitive b) =>
Value a -> CodeGenFunction r (Value b)
+sitofp :: (IsInteger a, IsFloating b, NumberOfElements n a,
NumberOfElements n b) => Value a -> CodeGenFunction r (Value b)
 sitofp = convert FFI.buildSIToFP

 -- | Convert a pointer to an integer.
diff -rN -u old-llvm-0.8-merge/LLVM/Core/Type.hs
new-llvm-0.8-merge/LLVM/Core/Type.hs
--- old-llvm-0.8-merge/LLVM/Core/Type.hs        2010-07-24
19:24:08.000000000 +0200
+++ new-llvm-0.8-merge/LLVM/Core/Type.hs        2010-07-24
19:24:08.000000000 +0200
@@ -17,6 +17,8 @@
     IsFirstClass,
     IsSized,
     IsFunction,
+    -- ** Others
+    NumberOfElements,
     UnknownSize, -- needed for arrays of structs
     -- ** Structs
     (:&), (&),
@@ -129,7 +131,11 @@
 -- Usage:
 --  Precondition for Vector
 -- |Primitive types.
-class IsType a => IsPrimitive a
+class (NumberOfElements D1 a) => IsPrimitive a
+
+-- |Number of elements for instructions that handle both primitive and
vector types
+class (IsType a) => NumberOfElements n a | a -> n
+

 -- Usage:
 --  Precondition for function args and result.
@@ -346,6 +352,28 @@
 instance IsPrimitive Label
 instance IsPrimitive ()

+
+instance NumberOfElements D1 Float
+instance NumberOfElements D1 Double
+instance NumberOfElements D1 FP128
+instance (Pos n) => NumberOfElements D1 (IntN n)
+instance (Pos n) => NumberOfElements D1 (WordN n)
+instance NumberOfElements D1 Bool
+instance NumberOfElements D1 Int8
+instance NumberOfElements D1 Int16
+instance NumberOfElements D1 Int32
+instance NumberOfElements D1 Int64
+instance NumberOfElements D1 Word8
+instance NumberOfElements D1 Word16
+instance NumberOfElements D1 Word32
+instance NumberOfElements D1 Word64
+instance NumberOfElements D1 Label
+instance NumberOfElements D1 ()
+
+instance (Nat n, IsPrimitive a) =>
+         NumberOfElements n (Vector n a)
+
+
 -- Functions.
 instance (IsFirstClass a, IsFunction b) => IsFunction (a->b) where
     funcType ts _ = funcType (typeDesc (undefined :: a) : ts)
(undefined :: b)




More information about the Haskell-llvm mailing list