Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,251
    • Issues 4,251
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 394
    • Merge Requests 394
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #9638

Closed
Open
Opened Sep 26, 2014 by David Feuer@treeowlReporter

Speed up Data.Char.isDigit

isDigit is currently defined like this:

isDigit                 :: Char -> Bool
isDigit c               =  c >= '0' && c <= '9'

This will short-circuit the right way if you're looking for digits mixed with spaces, but the wrong way if you're looking for digits mixed with letters. It also requires a conditional jump to do that short-circuiting (confirmed by inspecting the assembly). It should be better to use an unsigned comparison instead:

isDigit                 :: Char -> Bool
isDigit c               = (fromIntegral (ord c) :: Word) - 48 <= 9

The interesting section looks like this

        movq 7(%rbx),%rax
        addq $-48,%rax
        cmpq $9,%rax
        setbe %al
        movzbl %al,%eax
        shlq $3,%rax
        movq ghczmprim_GHCziTypes_Bool_closure_tbl(%rax),%rbx
        addq $8,%rbp
        jmp *(%rbp)

or like this with -fllvm:

        movq    7(%rbx), %rax
        addq    $-48, %rax
        cmpq    $10, %rax
        sbbq    %rax, %rax
        andq    $8, %rax
        movq    ghczmprim_GHCziTypes_Bool_closure_tbl(%rax), %rbx
        movq    8(%rbp), %rax
        addq    $8, %rbp
        jmpq    *%rax  # TAILCALL
Trac metadata
Trac field Value
Version 7.9
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Assignee
Assign to
8.0.1
Milestone
8.0.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#9638