-- | Bits and pieces on the bottom of the module dependency tree.
--      Also import the required constants, so we know what we're using.
--
--      In the interests of cross-compilation, we want to free ourselves
--      from the autoconf generated modules like "GHC.Settings.Constants"

module GHC.CmmToAsm.SPARC.Base (
        wordLength,
        wordLengthInBits,
        spillSlotSize,
        extraStackArgsHere,
        fits13Bits,
        is32BitInteger,
        largeOffsetError
)

where

import GHC.Prelude

import GHC.Utils.Panic

import Data.Int


-- On 32 bit SPARC, pointers are 32 bits.
wordLength :: Int
wordLength :: Int
wordLength = Int
4

wordLengthInBits :: Int
wordLengthInBits :: Int
wordLengthInBits
        = Int
wordLength Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
8

-- | We need 8 bytes because our largest registers are 64 bit.
spillSlotSize :: Int
spillSlotSize :: Int
spillSlotSize = Int
8


-- | We (allegedly) put the first six C-call arguments in registers;
--      where do we start putting the rest of them?
extraStackArgsHere :: Int
extraStackArgsHere :: Int
extraStackArgsHere = Int
23


{-# SPECIALIZE fits13Bits :: Int -> Bool, Integer -> Bool #-}
-- | Check whether an offset is representable with 13 bits.
fits13Bits :: Integral a => a -> Bool
fits13Bits :: forall a. Integral a => a -> Bool
fits13Bits a
x = a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= -a
4096 Bool -> Bool -> Bool
&& a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
4096

-- | Check whether an integer will fit in 32 bits.
--      A CmmInt is intended to be truncated to the appropriate
--      number of bits, so here we truncate it to Int64.  This is
--      important because e.g. -1 as a CmmInt might be either
--      -1 or 18446744073709551615.
--
is32BitInteger :: Integer -> Bool
is32BitInteger :: Integer -> Bool
is32BitInteger Integer
i
        = Int64
i64 Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int64
0x7fffffff Bool -> Bool -> Bool
&& Int64
i64 Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
>= -Int64
0x80000000
        where i64 :: Int64
i64 = Integer -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
i :: Int64


-- | Sadness.
largeOffsetError :: (Show a) => a -> b
largeOffsetError :: forall a b. Show a => a -> b
largeOffsetError a
i
  = String -> b
forall a. String -> a
panic (String
"ERROR: SPARC native-code generator cannot handle large offset ("
                String -> String -> String
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
i String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
");\nprobably because of large constant data structures;" String -> String -> String
forall a. [a] -> [a] -> [a]
++
                String
"\nworkaround: use -fllvm on this module.\n")