Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3952262
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:49:47+00:00 2026-05-20T01:49:47+00:00

There is this simple function which I have used with C++ in the past

  • 0

There is this simple function which I have used with C++ in the past to simulate simple forms of tessellation. The function takes a number and a divisor. The divisor must be (a power of two – 1) and n should be between 0 and divisor. It returns a modulus result of n % (d+1) using bitwise &.

Fairly sure the function goes like:

unsigned int BitwiseMod(unsigned int n, unsigned int d){ return n & d; }

I am wanting to use this effectively in OpenCL and am wondering if it will work as I imagine it too. In my mind, modulus is a very expensive operation on the GPU but I am familiar using it to form magnitude spaces and other techniques to travel through data.

More often, I would be more likely to simply write this assuming functions have some overhead.

x[i] = 8*(i&d)+offset[i];  //OR in other contexts,...

num = i&d+offset[i];
x[num] = data;

The question is: Will this be useful or get in the way, if useful can you give me some examples where I might try to apply it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:49:47+00:00Added an answer on May 20, 2026 at 1:49 am

    On NVidia’s architectures, GT200 and up, Modulo isn’t particularly slow, not slower than a normal integer divide. See this paper for details.

    However, using a bitwise AND is still quite a lot faster. As function calls are expensive on GPUs, OpenCL compilers aggressively use inlining to improve performance by default. You should be fine with a function call, as it will be inlined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is probably is simple fix for this but I currently have code similar
There has to be a simple explanation for this. I have a parent <div>
I am sure there is a simple answer to this one. I have a
I'm sure this is a relatively simple question, and there must be a good
I have some simple function in Flex in which I would like to send
I hope this is a simple enough question for any SQL people out there...
I'm new with Objective-C, so there probably is a simple solution to this. I
PHP functions such as 'array_map' take a callback, which can be a simple function
This is a purely theoretical question. Given three simple classes: class Base { }
This is what I've got. It works. But, is there a simpler or better

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.