- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I'm struggling with adding int4 data. I want to be able to add two 96b numbers (what implies adding with carry) in my kernel and I came up with this code:
uint4 Add(uint4 a, uint4 b){
ulong c = {0};
c = (ulong)a+(ulong)b;
for(int i=1; i<3; i++){
c = (ulong)a+(ulong)b + (c>>32);
}
return (uint4)(c,c,c,0);
}
However, I noticed that typecasting significantly increases my resource usage. I'd appreciate if anyone could help me with finding a better solution.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In OpenCL C language you cannot dynamically index into vector types. That is a and b as used above is not allowed. You could do the following instead:
uint4 Add(uint4 a, uint4 b){ ulong4 c; c.s0 = (ulong) a.s0 + (ulong) b.s0; c.s1 = (ulong) a.s1 + (ulong) b.s1 + (c.s0 >> 32); c.s2 = (ulong) a.s2 + (ulong) b.s2 + (c.s1 >> 32); return (uint4)(c.s0, c.s1, c.s2, 0); }- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wow, thank you so much! I didn't realize it before, as it worked (despite great resource usage) properly. I lowered my logic utilization tremendously thanks to your advice, thank you again!

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page