MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / fizz_buzz_copy_strings

Function fizz_buzz_copy_strings

compute/example/fizz_buzz.cpp:81–107  ·  view source on GitHub ↗

second-pass kernel which copies the fizz-buzz string for each number to buffer using the previously calculated offsets.

Source from the content-addressed store, hash-verified

79 // second-pass kernel which copies the fizz-buzz string for each number to
80 // buffer using the previously calculated offsets.
81 __kernel void fizz_buzz_copy_strings(__global const uint *offsets, __global char *buffer)
82 {
83 const uint i = get_global_id(0);
84 const uint n = i + 1;
85 const uint offset = offsets[i];
86
87 if((n % 5 == 0) && (n % 3 == 0)){
88 copy_string("fizzbuzz\n", 9, buffer + offset);
89 }
90 else if(n % 5 == 0){
91 copy_string("fizz\n", 5, buffer + offset);
92 }
93 else if(n % 3 == 0){
94 copy_string("buzz\n", 5, buffer + offset);
95 }
96 else {
97 // convert number to string and write it to the output
98 __global char *number = buffer + offset;
99 uint n_ = n;
100 while(n_){
101 *number++ = (n_%10) + '0';
102 n_ /= 10;
103 }
104 reverse_string(buffer + offset, number - 1);
105 *number = '\n';
106 }
107 }
108);
109
110int main()

Callers

nothing calls this directly

Calls 2

copy_stringFunction · 0.85
reverse_stringFunction · 0.85

Tested by

no test coverage detected