{"id":16661388,"url":"https://github.com/bodigrim/quote-quot","last_synced_at":"2025-03-16T23:31:40.808Z","repository":{"id":42175695,"uuid":"324413592","full_name":"Bodigrim/quote-quot","owner":"Bodigrim","description":"Divide without division","archived":false,"fork":false,"pushed_at":"2024-10-14T22:24:36.000Z","size":23,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-27T15:17:13.238Z","etag":null,"topics":["code-generation","hackers-delight","integer-division","long-multiplication","strength-reduction","template-haskell"],"latest_commit_sha":null,"homepage":"http://hackage.haskell.org/package/quote-quot","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bodigrim.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-25T18:30:21.000Z","updated_at":"2024-10-14T22:24:40.000Z","dependencies_parsed_at":"2024-04-28T16:50:22.725Z","dependency_job_id":null,"html_url":"https://github.com/Bodigrim/quote-quot","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"6912aad83d3a1dc3914feae391c436c86a2d50a6"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bodigrim%2Fquote-quot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bodigrim%2Fquote-quot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bodigrim%2Fquote-quot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bodigrim%2Fquote-quot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bodigrim","download_url":"https://codeload.github.com/Bodigrim/quote-quot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243835952,"owners_count":20355611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generation","hackers-delight","integer-division","long-multiplication","strength-reduction","template-haskell"],"created_at":"2024-10-12T10:34:48.659Z","updated_at":"2025-03-16T23:31:40.157Z","avatar_url":"https://github.com/Bodigrim.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# quote-quot [![Hackage](http://img.shields.io/hackage/v/quote-quot.svg)](https://hackage.haskell.org/package/quote-quot) [![Stackage LTS](http://stackage.org/package/quote-quot/badge/lts)](http://stackage.org/lts/package/quote-quot) [![Stackage Nightly](http://stackage.org/package/quote-quot/badge/nightly)](http://stackage.org/nightly/package/quote-quot)\n\nGenerate routines for integer division, employing arithmetic\nand bitwise operations only, which are __2.5x-3.5x faster__\nthan `quot`. Divisors must be known\nin compile-time and be positive.\n\n```haskell\n{-# LANGUAGE TemplateHaskell #-}\n{-# OPTIONS_GHC -ddump-splices -ddump-simpl -dsuppress-all #-}\nimport Numeric.QuoteQuot\n\n-- Equivalent to (`quot` 10).\nquot10 :: Word -\u003e Word\nquot10 = $$(quoteQuot 10)\n```\n\n```haskell\n\u003e\u003e\u003e quot10 123\n12\n```\n\nHere `-ddump-splices` demonstrates the chosen implementation\nfor division by 10:\n\n```haskell\nSplicing expression quoteQuot 10 ======\u003e\n((`shiftR` 3) . ((\\ (W# w_a9N4) -\u003e\n  let !(# hi_a9N5, _ #) = (timesWord2# w_a9N4) 14757395258967641293##\n  in W# hi_a9N5) . id))\n```\n\nAnd `-ddump-simpl` demonstrates generated Core:\n\n```haskell\n quot10 = \\ x_a5t2 -\u003e\n   case x_a5t2 of { W# w_acHY -\u003e\n   case timesWord2# w_acHY 14757395258967641293## of\n   { (# hi_acIg, ds_dcIs #) -\u003e\n   W# (uncheckedShiftRL# hi_acIg 3#)\n   }\n   }\n```\n\nBenchmarks show that this implementation is __3.5x faster__\n than ``(`quot` 10)``:\n\n```haskell\n{-# LANGUAGE TemplateHaskell #-}\nimport Data.List\nimport Numeric.QuoteQuot\nimport System.CPUTime\n\nmeasure :: String -\u003e (Word -\u003e Word) -\u003e IO ()\nmeasure name f = do\n  t0 \u003c- getCPUTime\n  print $ foldl' (+) 0 $ map f [0..100000000]\n  t1 \u003c- getCPUTime\n  putStrLn $ name ++ \" \" ++ show ((t1 - t0) `quot` 1000000000) ++ \" ms\"\n{-# INLINE measure #-}\n\nmain :: IO ()\nmain = do\n  measure \"     (`quot` 10)\"      (`quot` 10)\n  measure \"$$(quoteQuot 10)\" $$(quoteQuot 10)\n```\n\n```\n499999960000000\n     (`quot` 10) 316 ms\n499999960000000\n$$(quoteQuot 10)  89 ms\n```\n\nConventional wisdom is that such microoptimizations are negligible in practice,\nbut this is not always the case. For instance, quite surprisingly,\nthis trick alone\n[made Unicode normalization of Hangul characters twice faster](https://github.com/composewell/unicode-transforms/pull/42)\nin [`unicode-transforms`](http://hackage.haskell.org/package/unicode-transforms).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbodigrim%2Fquote-quot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbodigrim%2Fquote-quot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbodigrim%2Fquote-quot/lists"}