packages feed

fir-0.1.0.0: test/Tests/Bits/BitCast.hs

{-# LANGUAGE BlockArguments   #-}
{-# LANGUAGE DataKinds        #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators    #-}

module Tests.Bits.BitCast where

-- fir
import FIR

------------------------------------------------
-- program

type Defs = '[ "x"    ':-> Input  '[Location 0] Word32
             , "y"    ':-> Input  '[Location 1] Int32
             , "out"  ':-> Output '[Location 0] Word32
             , "main" ':-> EntryPoint '[] Vertex
             ]

program :: Module Defs
program = Module $ entryPoint @"main" @Vertex do
  x <- get @"x"
  y <- get @"y"
  -- Reinterpret between signed and unsigned integers, and floating-point numbers.
  let
    signed :: Code Int32
    signed = bitcast x
    float :: Code Float
    float = bitcast y
  put @"out" ( bitcast ( signed `shiftR` ( 1 :: Code Word32 ) ) + bitcast float )