adding isWHNF primop to 5.00.2 native code generator
Simon Marlow
simonmar@microsoft.com
Wed, 1 Aug 2001 11:28:32 +0100
> \begin{code}
> primCode [res] IsHNF [arg]
> =3D let res' =3D amodeToStix res
> arg' =3D amodeToStix arg
> arg_info =3D StInd PtrRep arg'
> word_32 =3D StInd WordRep (StIndex PtrRep=20
> arg_info (StInt (-1)))
> masked_le32 =3D StPrim SrlOp [word_32, StInt 16]
> masked_be32 =3D StPrim AndOp [word_32, StInt 65535]
> #ifdef WORDS_BIGENDIAN
> ty_info =3D masked_le32
> #else
> ty_info =3D masked_be32
> #endif
> not_a_thunk =3D StPrim IntEqOp [ StPrim AndOp=20
> [ty_info, StInt 0x10]
> , StInt 0x0
> ]
> -- ToDo: don't hardwire the value of=20
> _THUNK from InfoTables.h
> assign =3D StAssign IntRep res' not_a_thunk
> in
> returnUs (\ xs -> assign : xs)
> \end{code}=20
This code looks bogus - it is checking a bit in the info table, which
would have been correct when we used to store flags in the info table,
but that changed a while back.
closure_THUNK() works by getting the type field (i.e.
get_itbl(c)->type), and using that to index into the table of closure
flags (see ghc/rts/ClosureFlags.c), and checking the "THU" flag. This
is the portable way to do it. The hacky way to do it would be to
compare against the closure types directly - fortunately you can use the
names rather than the constants, see ghc/compiler/codeGen/SMRep.lhs.
Cheers,
Simon