Skip to content

Instantly share code, notes, and snippets.

View Abhiroop's full-sized avatar
:electron:
"Syntactic sugar causes cancer of the semicolon."

Abhiroop Sarkar Abhiroop

:electron:
"Syntactic sugar causes cancer of the semicolon."
View GitHub Profile
@Abhiroop
Abhiroop / foo.java
Created January 29, 2021 07:54
foo
file
@Abhiroop
Abhiroop / FinalEvaluation.md
Last active September 11, 2018 18:34
GSoC final evaluation

Overview of Vectorization support in GHC

With the completion of GSoC 2018, this project has completed an initial step to introduce basic vectorization functions to the Glasgow Haskell Compiler. At the end of this project my branch of GHC (https://github.com/Abhiroop/ghc-1/tree/wip/simd-ncg-support) supports:

Among constructors and de-constructors

broadcastFloatX4# :: Float# -> FloatX4#
#include <stdio.h>
#include <smmintrin.h> //SSE4_1
#include <emmintrin.h> //SSE2
void print128_num(__m128i var)
{
//int64_t *v64val = (int64_t*) &var;
//printf("%.16llx %.16llx\n", v64val[1], v64val[0]);
diff --git a/compiler/cmm/CmmCallConv.hs b/compiler/cmm/CmmCallConv.hs
index e1067e9..241a8f5 100644
--- a/compiler/cmm/CmmCallConv.hs
+++ b/compiler/cmm/CmmCallConv.hs
@@ -66,7 +66,7 @@ assignArgumentsPos dflags off conv arg_ty reps = (stk_off, assignments)
| otherwise = int
where vec = case (w, regs) of
(W128, (vs, fs, ds, ls, s:ss))
- | passVectorInReg W128 dflags -> k (RegisterParam (XmmReg s), (vs, fs, ds, ls, ss))
+ | passVectorInReg W128 dflags -> k (RegisterParam (XmmReg s 4 W32), (vs, fs, ds, ls, ss))
This is write up on how we go about enriching the Xmm, Ymm, Zmm registers of the GlobalReg type with more information.
Here we are talking about all the places where the GlobalReg type is being used.
compiler/cmm/Cmm.hs
CmmProc constructor of the GenCmmDecl data types has a field which hold a list of live GlobalRegs. This represents the list of
live GlobalRegs
compiler/cmm/CmmCallConv.hs
for a simple function like this:
```
main :: IO ()
main
= case unpackFloatX4# (packFloatX4# (# 9.2#, 8.15#, 7.0#, 6.4# #)) of
(# a, b, c, d #) -> print (F# a, F# b, F# c, F# d)
```
Some background:
#include <stdio.h>
#include <xmmintrin.h> //SSE
inline __m64 shuf(int perm){
__m64 a = _mm_setr_pi16(1,2,3,4);
return _mm_shuffle_pi16 (a, perm);
}
int main()
{
;; Bear in mind this is a literal translation of the Haskell partitionBy.
;; This might not be the most idiomatic clojure.
(defn partition-by'' [f head tail]
(if (empty? tail)
(cons [head] tail)
(let [generator (partition-by'' f (first tail) (next tail))]
(if (= (f head) (f (first tail)))
(cons (cons head (first generator)) (next generator))
partitionBy :: Eq b => (a -> b) -> [a] -> [[a]]
partitionBy f [] = []
partitionBy f [x] = [[x]]
partitionBy f l = partitionBy' f (head l) (tail l)
partitionBy' _ x [xs] = [x : [xs]]
partitionBy' f x xs@(x':_)
| (f x) == (f x') = (x : (head generator)) : (tail generator) -- the recursion is delayed here by lazily creating a generator
| otherwise = [x] : generator
where
pascalLevel :: [[Int]]
pascalLevel = [1] : map foo pascalLevel
foo :: [Int] -> [Int]
foo x = zipWith (+) ([0] ++ x) (x ++ [0])
-- take 5 pascalLevel
-- [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
-------------------------------------------------------