[GHC] #13212: Support abs as a primitive operation on floating point numbers.

#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

#13212: Support abs as a primitive operation on floating point numbers. -------------------------------------+------------------------------------- Reporter: dominic | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by rwbarton): * keywords: => newcomer Comment: Yes, this would be worthwhile and not difficult. See https://ghc.haskell.org/trac/ghc/wiki/Commentary/PrimOps#AddinganewPrimOp for the steps involved and https://phabricator.haskell.org/D1334 for a recent example. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13212#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13212: Support abs as a primitive operation on floating point numbers. -------------------------------------+------------------------------------- Reporter: dominic | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): See also #7858, which fixed the definition of `abs` and `signum`. There it was suggested that a ticket be created for making the implementation more efficient, but as far as I can tell no one ever did so (until now). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13212#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13212: Support abs as a primitive operation on floating point numbers. -------------------------------------+------------------------------------- Reporter: dominic | Owner: dominic Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dominic): * owner: => dominic Comment: I am happy to give this a go. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13212#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13212: Support abs as a primitive operation on floating point numbers. -------------------------------------+------------------------------------- Reporter: dominic | Owner: dominic Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dominic): I have this working. I am not sure what sort of test to put in. Maybe just keep the current one? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13212#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13212: Support abs as a primitive operation on floating point numbers. -------------------------------------+------------------------------------- Reporter: dominic | Owner: dominic Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dominic): * status: new => closed * resolution: => fixed Comment: Fixed by 12ccf767af3373e319b75d5d61fe79df4a389e45 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13212#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC