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
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]]
-------------------------------------------------------
delL x t@(T R t1 y t2) = T R (del x t1) y t2
delR x t@(T R t1 y t2) = T R t1 y (del x t2)
delL :: (Ord a) => a -> Tree a -> Tree a
delR :: (Ord a) => a -> Tree a -> Tree a
data Nat = Zero | Succ Nat
data T n a = NodeR (Tree n a) a (Tree (Succ n) a) -- right subtree has height + 1
| NodeL (Tree (Succ n) a) a (Tree n a) -- left subtree has height + 1
| Node (Tree n a) a (Tree n a) -- both subtrees are of equal height
data Tree n a where
Branch :: T n a -> Tree (Succ n) a
Leaf :: Tree Zero a
{-# LANGUAGE GADTs, DataKinds #-}