 
         do
         {
-            addIonsAB(b_mass, (float) charge, spec);
-            addIonsY (y_mass, (float) charge, spec);
+            addIonsAB(b_mass, (float) charge, spec, len_spec);
+            addIonsY (y_mass, (float) charge, spec, len_spec);
         }
         while (++charge < max_charge);
     }

 * corresponding to the neutral losses of H2O and NH3.
 */
__device__ void
addIonsAB(float mass, float charge, int *spec)
{
    // A
    atomicMax(&spec[bin(ionMZ(mass - massCO, charge))], 10);

    // B
    float m = ionMZ(mass, charge);
    int   b = bin(m);

    atomicMax(&spec[b],   50);
    atomicMax(&spec[b+1], 25);
    atomicMax(&spec[b-1], 25);
    atomicMax(&spec[bin(m - massH2O/charge)], 10);
    atomicMax(&spec[bin(m - massNH3/charge)], 10);
}


__device__ void
addIonsY(float mass, float charge, int *spec)
{
    float m = ionMZ(mass + massH2O, charge);
    int   b = bin(m);

    atomicMax(&spec[b],   50);
    atomicMax(&spec[b+1], 25);
    atomicMax(&spec[b-1], 25);
    atomicMax(&spec[bin(m - massNH3/charge)], 10);
}



    unsigned int threads = min(ceilPow2(len_ions), 512);
    unsigned int blocks  = (len_ions + threads - 1) / threads;

    if (isPow2(len_ions))
        addIons_core<true><<<blocks,threads>>>(max_charge, b_ions, y_ions, spec, len_ions, len_spec);
    else
        addIons_core<false><<<blocks,threads>>>(max_charge, b_ions, y_ions, spec, len_ions, len_spec);
}

