
On 03 October 2004 14:07, Tomasz Zielonka wrote:
Then I noticed the cause: GHC.Prim.<# returns a boxed, heap allocated Bool, and so do other primitive comparison operators.
Would it be difficult to add Bool unboxing to GHC? Maybe it would suffice to use preallocated False and True?
Just to clarify a little more: although the raw primitive operations do appear to return fully boxed True & False values, in practice they rarely do, because the code genrator optimises case a >=# b of True -> e1 False -> e2 to if (a >=# b) { .. code for e1 ... } else { .. code for e2 .. } (well, more or less). Only if the result of the comparison is actually being returned from a function does it get turned into a real Bool. It would probably be better to return 0#/1# instead of a Bool from the comparison primops, because this would expose slightly more detail to the simplifier and might result in slightly better code in some cases (but no dramatic improvements). It would also let us remove a bit of complexity from the code generator. Cheers, Simon

On Tue, Oct 05, 2004 at 01:48:30PM +0100, Simon Marlow wrote:
It would probably be better to return 0#/1# instead of a Bool from the comparison primops, because this would expose slightly more detail to the simplifier and might result in slightly better code in some cases (but no dramatic improvements). It would also let us remove a bit of complexity from the code generator.
This seems like it could be nicely generalized such that all enumeration types unbox to the unboxed integer of their offset. so data Perhaps = Yes | Maybe | No can unbox to an Int# with 0# == Yes 1# == Maybe and 2# == No. Then we get the Bool optimization for free. John -- John Meacham - ⑆repetae.net⑆john⑈
participants (2)
-
John Meacham
-
Simon Marlow