From 40d8f3aeedf018c7c6766e98ec64733abd90671e Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 16 Sep 2019 09:38:21 -0400 Subject: CPU Performance/Testing improvements (#1055) * First pass of render-test refactor. * Make window construction a function that can choose an implementation. * Remove OpenGL as currently has windows dependency. * Disable Vulkan as Renderer impl has dependency on windows. * Pass Window in as parameter of 'update'. * Add win-window.cpp as was missing. * Fix warning on windows about signs during comparison. * * Added mechanism to add random arrays as buffer inputs and select type * Improved RenderGenerator to generate more types, and to be more careful around int32 ranges. * Added support for security checks (for Visual Studio C++) * Disable Execption handling being on by default when compiling kernels * Added a 'Group' version of the entry point that will evaluate all threads in a group in a single call. In test code use this method if available. * Added -compile-arg to be able to pass arguments to the compile within render-test * Add documention for the _Group execution feature. * Fix some typos in cpu-target.md --- source/core/slang-random-generator.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'source/core/slang-random-generator.cpp') diff --git a/source/core/slang-random-generator.cpp b/source/core/slang-random-generator.cpp index 7e8476c30..ce43067aa 100644 --- a/source/core/slang-random-generator.cpp +++ b/source/core/slang-random-generator.cpp @@ -32,15 +32,33 @@ int64_t RandomGenerator::nextInt64() return (int64_t(high) << 32) | low; } -int32_t RandomGenerator::nextInt32InRange(int32_t min, int32_t max) +uint32_t RandomGenerator::nextUInt32InRange(uint32_t min, uint32_t max) { - int32_t diff = max - min; + // Make sure max is at least in + max = (max >= min) ? max : min; + + // Make 64 bit so can be lazier than having to take care of 32 bit overflow/underflow issues + uint32_t diff = max - min; if (diff <= 1) { return min; } + return (nextUInt32() % diff) + min; +} - return (nextPositiveInt32() % diff) + min; + +int32_t RandomGenerator::nextInt32InRange(int32_t min, int32_t max) +{ + // Make sure max is at least in + max = (max >= min) ? max : min; + + // Make 64 bit so can be lazier than having to take care of 32 bit overflow/underflow issues + uint32_t diff = uint32_t(int64_t(max) - int64_t(min)); + if (diff <= 1) + { + return min; + } + return int32_t(int64_t(nextUInt32() % diff) + min); } int64_t RandomGenerator::nextInt64InRange(int64_t min, int64_t max) -- cgit v1.2.3