Cycles: use intrinsics for fast_rint #107371

Merged
Sergey Sharybin merged 1 commits from xavierh/blender:intrinsics_rintf into main 2023-04-28 18:49:53 +02:00
Member

MSVC can't optimize it out and even keeps an external call to CRT
function rintf: https://godbolt.org/z/Ex9vjf8vj

It does translate to a real speedup on windows on some scenes, here are the ratios I had on my 13900K:
classroom 101.53%
junkshop 100.71%
monster 100.76%
attic 107.98%
bistro 113.00%

MSVC can't optimize it out and even keeps an external call to CRT function rintf: https://godbolt.org/z/Ex9vjf8vj It does translate to a real speedup on windows on some scenes, here are the ratios I had on my 13900K: classroom 101.53% junkshop 100.71% monster 100.76% attic 107.98% bistro 113.00%
Xavier Hallade added 1 commit 2023-04-26 15:26:02 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
587f2e9583
Cycles: use intrinsics for fast_rint
MSVC can't optimize it out and even keeps an external call to CRT
function rintf: https://godbolt.org/z/Ex9vjf8vj
Xavier Hallade added the
Module
Render & Cycles
label 2023-04-26 15:26:28 +02:00
Xavier Hallade added this to the 3.6 LTS milestone 2023-04-26 15:26:33 +02:00
Xavier Hallade added this to the Render & Cycles project 2023-04-26 15:26:41 +02:00
Xavier Hallade requested review from Brecht Van Lommel 2023-04-26 15:26:55 +02:00
Xavier Hallade requested review from Sergey Sharybin 2023-04-26 15:26:56 +02:00
Brecht Van Lommel approved these changes 2023-04-26 19:28:53 +02:00

@blender-bot build

@blender-bot build

That is quite some speedup! Just to confirm, does it keep the same precision?

As for the failure in the arm64 i've created #107396 which should solve it.

That is quite some speedup! Just to confirm, does it keep the same precision? As for the failure in the arm64 i've created #107396 which should solve it.
Author
Member

Yes precision is the same - you can check the assembly on the godbolt.org link.
The only difference in gcc's generated assembly is the rounding control value, which when you use rintf() is set to _MM_FROUND_CUR_DIRECTION and then uses what's in MXCSR register which is nearest by default, while in my proposed version I've put (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC) explicitly.

Yes precision is the same - you can check the assembly on the godbolt.org link. The only difference in gcc's generated assembly is the rounding control value, which when you use rintf() is set to _MM_FROUND_CUR_DIRECTION and then uses what's in MXCSR register which is nearest by default, while in my proposed version I've put (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC) explicitly.

Thanks for the explanation. The code seems fine, just need to avoid breaking arm64 platform (as in, need to land #107396 first).

Thanks for the explanation. The code seems fine, just need to avoid breaking arm64 platform (as in, need to land #107396 first).

@blender-bot build

@blender-bot build
Sergey Sharybin merged commit 252b0a023e into main 2023-04-28 18:49:53 +02:00
Sergey Sharybin deleted branch intrinsics_rintf 2023-04-28 18:49:54 +02:00
Brecht Van Lommel removed this from the Render & Cycles project 2023-05-24 19:05:21 +02:00
Howard Trickey referenced this issue from a commit 2023-05-29 02:51:43 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#107371
No description provided.