
#13212: Support abs as a primitive operation on floating point numbers. -------------------------------------+------------------------------------- Reporter: dominic | Owner: Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Haskell differs from C and FORTRAN on the manner in which it computes the absolute value of floating point numbers. Both FORTRAN and C support a `fabs` primitive function that is compiled directly to the underlying `fabs` machine instruction on either AMD64 or Intel x86 processors (with a small amount of stack manipulation). Haskell, however, does not support `abs` as a primitive operation on floating point numbers. Instead, Haskell desugars `abs` to the following: abs x | x == 0 = 0 -- handles (-0.0) | x > 0 = x | otherwise = negateFloat x Rather than calling the utilizing the `fabs` mnemonic or twiddling the sign bit, both of which can be executed in a single instruction, this implementation results in ~15 machine instructions and requires ~4-5 times the number of clock cycles to execute. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13212 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler