]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commit
ggml : avoid duplicating function calls using MIN/MAX macros (#5325)
authorDr. Tom Murphy VII Ph.D <redacted>
Mon, 5 Feb 2024 11:13:57 +0000 (06:13 -0500)
committerGitHub <redacted>
Mon, 5 Feb 2024 11:13:57 +0000 (13:13 +0200)
commitabb61944a5f64dec62c893ed0db10790169b672a
tree9ba841d2219cc0ea717a792e6c2e63a3fa4baa9d
parent89503dcb5f764a5cc7093db1f395f5121876a2cc
ggml : avoid duplicating function calls using MIN/MAX macros (#5325)

* Avoid duplicating function calls when using MIN/MAX macros.

Since these copy "a" and "b" they ask the compiler to evaluate one of them twice. The compiler doesn't have a problem with removing the duplication in something like MAX(0, x + 2), but in some cases we're calling functions, and those calls just happen twice.
By explicitly evaluating at the expression we get smaller and faster code without duplicate calls. See ggml_rope_yarn_corr_dims in Compiler Explorer:

https://godbolt.org/z/Ee4KMrvKh

Code behaves exactly the same.

* Update ggml.c

---------

Co-authored-by: Georgi Gerganov <redacted>
ggml.c