diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2014-03-16 22:09:28 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2014-03-16 22:09:28 +0100 |
commit | c27fb4116eaa6b43c1e132e5e50d636c549ed122 (patch) | |
tree | 08ccb8fc8473a9e5f6fcecb43c7acd709087259f | |
parent | 9d4b77a65a0b3283dea57aa9cc189eee5aa492ea (diff) | |
parent | dd18c0ddd50f1e1f60a5f4337772198af77aebfa (diff) | |
download | Nim-c27fb4116eaa6b43c1e132e5e50d636c549ed122.tar.gz |
Merge pull request #1000 from gradha/pr_adds_likely_example_983
Adds example to likely/unlikely docstring. Refs #983.
-rw-r--r-- | lib/system.nim | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/system.nim b/lib/system.nim index 41624bb05..be57ba192 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2364,12 +2364,32 @@ when not defined(JS): #and not defined(NimrodVM): when not defined(NimrodVM): proc likely*(val: bool): bool {.importc: "likely", nodecl, nosideeffect.} - ## can be used to mark a condition to be likely. This is a hint for the - ## optimizer. + ## Hints the optimizer that `val` is likely going to be true. + ## + ## You can use this proc to decorate a branch condition. On certain + ## platforms this can help the processor predict better which branch is + ## going to be run. Example: + ## + ## .. code-block:: nimrod + ## for value in inputValues: + ## if likely(value <= 100): + ## process(value) + ## else: + ## echo "Value too big!" proc unlikely*(val: bool): bool {.importc: "unlikely", nodecl, nosideeffect.} - ## can be used to mark a condition to be unlikely. This is a hint for the - ## optimizer. + ## Hints the optimizer that `val` is likely going to be false. + ## + ## You can use this proc to decorate a branch condition. On certain + ## platforms this can help the processor predict better which branch is + ## going to be run. Example: + ## + ## .. code-block:: nimrod + ## for value in inputValues: + ## if unlikely(value > 100): + ## echo "Value too big!" + ## else: + ## process(value) proc rawProc*[T: proc](x: T): pointer {.noSideEffect, inline.} = ## retrieves the raw proc pointer of the closure `x`. This is |