user30198: My original question was if there is a library that covers the internal comparator and differential and gain modes for the Arduino Uno, Mega 2560, Leonardo, Due, Zero, M0.
The answer is obvious: "No". To my surprise there is not even a start to make it and neither a collaboration to gather usefull code. 
If you know pieces of code (Arduino compatible and documentation for which pins) for the analog comparator and gain, then please tell me about it, and I put them in this list.

analogComp, a library to manage the analog comparator.
To use the analog comparator for the ATmega8, Arduino Uno, Leonardo, Mega 2560, ATtiny85, and others. A routine is called with an interrupt every time a particolar condition happens.
Arduino Differential ADC and Gain ADC
A file "wiring_differential.c" should be added to the Arduino files. Functions "analogReadDiff" and "analogReadGain" will be added. For the Arduino Leonardo and the Arduino Mega 2560.
Nick Gammon: Using the Arduino Analog Comparator
A simple example of a comparator mode for the ATmega328.
Application Note AT11480: Analog Comparator Application Examples
Using the Analog Comparator for SAM D (that includes the ATSAMD21 of the Arduino Zero and M0) processors. 


user30002: You seem to be interested mainly in ATSAMD21. There is an application note from Atmel, AT11480: Analog Comparator Application Examples, which may be of interest for you.
From the Getting started section (3.1, page 8):

The AC [Analog Comparator] example project has to be opened from New
  Example Project option in Atmel Studio. Using the option Atmel Studio
  → File → New → Example Project will open the New Example Project from
  ASF or Extensions window. The project named Analog Comparator Examples
  – SAM D21 Xplained Pro has to be opened.

There you'll find example code that might be useful for you, as it will show how to configure and manage the registers involved in using the analog comparator of the ATSAMD21. Namely, the example code is related to the following example applications:

Level crossing detector.
Window mode operation.
Preventing false spike detection.
Gray signal frequency measurement.
SleepWalking with analog comparator.

If you look into the first case (level crossing detector) for guidelines for where to start from, you can see that the application example goes through the following steps:

Enable alternate function H (AC/CMP[0]) for pin PA12 so that the comparator 0 output is directly routed to the pin.
Select GCLK Generator 0 as GCLK source for AC module. The GCLK Generator 0 is clocked from internal OSC8M oscillator whose output is set to 8MHz.
Select AIN[0] pin (PA04) as positive input and internal voltage scaler output as negative input for comparator 0. The voltage scaler register is set to a value of 9 corresponding to a voltage output of 0.5156V.
Set comparator 0 in continuous comparison mode with hysteresis and filter mode disabled.
Enable comparator 0 output to be routed to I/O pin and select interrupt mode as toggle so that comparator output toggles when positive input crosses the negative input (both during rising and falling).
Enable comparator 0 and then enable the AC module.

You could get from that example code some ideas about the registers to be configured and managed, and then try to use that knowledge for creating (or even reusing) some code within the Arduino IDE. 
Hope it helps...

user30002: I would recommend you to check Nick Gammon's example on using the analog comparator by means of configuring the relevant flag bits of registers in the ATmega328. Sample code from the link, by Nick:
volatile boolean triggered;

ISR (ANALOG_COMP_vect)
  {
  triggered = true;
  }

void setup ()
  {
  Serial.begin (115200);
  Serial.println ("Started.");
  ADCSRB = 0;           // (Disable) ACME: Analog Comparator Multiplexer Enable
  ACSR =  bit (ACI)     // (Clear) Analog Comparator Interrupt Flag
        | bit (ACIE)    // Analog Comparator Interrupt Enable
        | bit (ACIS1);  // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on falling edge)
   }  // end of setup

void loop ()
  {
  if (triggered)
    {
    Serial.println ("Triggered!"); 
    triggered = false;
    }

  }  // end of loop


30198: <p>My original question was if there is a library that covers the internal <strong>comparator</strong> and <strong>differential</strong> and <strong>gain</strong> modes for the Arduino Uno, Mega 2560, Leonardo, Due, Zero, M0.<br>
The answer is obvious: "No". To my surprise there is not even a start to make it and neither a collaboration to gather usefull code. </p>

<p>If you know pieces of code (Arduino compatible and documentation for which pins) for the analog comparator and gain, then please tell me about it, and I put them in this list.</p>

<ul>
<li><a href="http://www.leonardomiliani.com/en/2012/analogcomp-una-libreria-per-gestire-il-comparatore-analogico/" rel="nofollow noreferrer">analogComp</a>, a library to manage the analog comparator.<br>
To use the analog comparator for the ATmega8, Arduino Uno, Leonardo, Mega 2560, ATtiny85, and others. A routine is called with an interrupt every time a particolar condition happens.</li>
<li><a href="https://lawas.nahdhi.com/arduino-differential-adc-and-gain-adc.html" rel="nofollow noreferrer">Arduino Differential ADC and Gain ADC</a><br>
A file "wiring_differential.c" should be added to the Arduino files. Functions "analogReadDiff" and "analogReadGain" will be added. For the Arduino Leonardo and the Arduino Mega 2560.</li>
<li><a href="https://www.gammon.com.au/forum/?id=11916" rel="nofollow noreferrer">Nick Gammon: Using the Arduino Analog Comparator</a><br>
A simple example of a comparator mode for the ATmega328.</li>
<li><a href="http://www.atmel.com/Images/Atmel-42473-Analog-Comparator-Application-Examples_UserGuide_AT11480.pdf" rel="nofollow noreferrer">Application Note AT11480: Analog Comparator Application Examples</a><br>
Using the Analog Comparator for SAM D (that includes the ATSAMD21 of the Arduino Zero and M0) processors. </li>
</ul>
 30002: <p>You seem to be interested mainly in ATSAMD21. There is an application note from Atmel, <a href="http://www.atmel.com/Images/Atmel-42473-Analog-Comparator-Application-Examples_UserGuide_AT11480.pdf" rel="nofollow noreferrer">AT11480: Analog Comparator Application Examples</a>, which may be of interest for you.</p>

<p>From the <em>Getting started</em> section (3.1, page 8):</p>

<blockquote>
  <p>The AC [Analog Comparator] example project has to be opened from New
  Example Project option in Atmel Studio. Using the option Atmel Studio
  → File → New → Example Project will open the New Example Project from
  ASF or Extensions window. The project named Analog Comparator Examples
  – SAM D21 Xplained Pro has to be opened.</p>
</blockquote>

<p>There you'll find example code that might be useful for you, as it will show how to configure and manage the registers involved in using the analog comparator of the ATSAMD21. Namely, the example code is related to the following example applications:</p>

<ol>
<li>Level crossing detector.</li>
<li>Window mode operation.</li>
<li>Preventing false spike detection.</li>
<li>Gray signal frequency measurement.</li>
<li>SleepWalking with analog comparator.</li>
</ol>

<p>If you look into the first case (<strong>level crossing detector</strong>) for guidelines for where to start from, you can see that the application example goes through the following steps:</p>

<ol>
<li>Enable alternate function H (AC/CMP[0]) for pin PA12 so that the comparator 0 output is directly routed to the pin.</li>
<li>Select GCLK Generator 0 as GCLK source for AC module. The GCLK Generator 0 is clocked from internal OSC8M oscillator whose output is set to 8MHz.</li>
<li>Select AIN[0] pin (PA04) as positive input and internal voltage scaler output as negative input for comparator 0. The voltage scaler register is set to a value of 9 corresponding to a voltage output of 0.5156V.</li>
<li>Set comparator 0 in continuous comparison mode with hysteresis and filter mode disabled.</li>
<li>Enable comparator 0 output to be routed to I/O pin and select interrupt mode as toggle so that comparator output toggles when positive input crosses the negative input (both during rising and falling).</li>
<li>Enable comparator 0 and then enable the AC module.</li>
</ol>

<p>You could get from that example code some ideas about the registers to be configured and managed, and then try to use that knowledge for creating (or even reusing) some code within the Arduino IDE. </p>

<p>Hope it helps...</p>
 30002: <p>I would recommend you to check <a href="https://www.gammon.com.au/forum/?id=11916" rel="nofollow noreferrer">Nick Gammon's example on using the analog comparator</a> by means of configuring the relevant flag bits of registers in the ATmega328. Sample code from the link, by Nick:</p>

<pre><code>volatile boolean triggered;

ISR (ANALOG_COMP_vect)
  {
  triggered = true;
  }

void setup ()
  {
  Serial.begin (115200);
  Serial.println ("Started.");
  ADCSRB = 0;           // (Disable) ACME: Analog Comparator Multiplexer Enable
  ACSR =  bit (ACI)     // (Clear) Analog Comparator Interrupt Flag
        | bit (ACIE)    // Analog Comparator Interrupt Enable
        | bit (ACIS1);  // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on falling edge)
   }  // end of setup

void loop ()
  {
  if (triggered)
    {
    Serial.println ("Triggered!"); 
    triggered = false;
    }

  }  // end of loop
</code></pre>
