-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
write system.abs in nim, not magic #476
Comments
Implementing them as magics makes them could be folded in compile time of mAbsI: result = foldAbs(getInt(a), n, g) |
does it matter though? why would |
abs(-4) is folded into 4? |
|
indeed, const folding does happen for max/min as can be seen by looking at codegen for: when true:
func max2[T](a, b: T): T {.inline.} =
if a<b: b else: a
proc main()=
let a1 = max(11+1,12+2)
let a2 = max2(11+1,12+2)
echo (a1, a2)
main() => codegen shows (with
It feels very odd to have these hard-coded cases in the compiler. Even if const folding is desired (which should be justified; C compiler should already take care of this; I can't see how this can possibly generate different optimized binary code), why should a magic be used for that? Instead of, say, a flag (maybe enabled by I think for abs the cleanup doesn't require an RFC (abs is relatively rare) but maybe it's needed for other magics-that-shouldn't-be-magics like max,min etc. I'm curious in fact how many of them there are. |
regarding symbols that trigger const folding, IIUC it's handled by
|
what's the progress? |
refs nim-lang#16432 (comment)
and remove
mAbsI
magic, and then, in subsequent work, investigate whether the branchless bit hack https://graphics.stanford.edu/~seander/bithacks.html#IntegerAbs can improve performance in at least some cases ?The text was updated successfully, but these errors were encountered: