// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package fuzz

import (
	
	
)

// ResetCoverage sets all of the counters for each edge of the instrumented
// source code to 0.
func () {
	 := coverage()
	for  := range  {
		[] = 0
	}
}

// SnapshotCoverage copies the current counter values into coverageSnapshot,
// preserving them for later inspection. SnapshotCoverage also rounds each
// counter down to the nearest power of two. This lets the coordinator store
// multiple values for each counter by OR'ing them together.
func () {
	 := coverage()
	for ,  := range  {
		 |=  >> 1
		 |=  >> 2
		 |=  >> 4
		 -=  >> 1
		coverageSnapshot[] = 
	}
}

// diffCoverage returns a set of bits set in snapshot but not in base.
// If there are no new bits set, diffCoverage returns nil.
func diffCoverage(,  []byte) []byte {
	if len() != len() {
		panic(fmt.Sprintf("the number of coverage bits changed: before=%d, after=%d", len(), len()))
	}
	 := false
	for  := range  {
		if []&^[] != 0 {
			 = true
			break
		}
	}
	if ! {
		return nil
	}
	 := make([]byte, len())
	for  := range  {
		[] = [] &^ []
	}
	return 
}

// countNewCoverageBits returns the number of bits set in snapshot that are not
// set in base.
func countNewCoverageBits(,  []byte) int {
	 := 0
	for  := range  {
		 += bits.OnesCount8([] &^ [])
	}
	return 
}

// isCoverageSubset returns true if all the base coverage bits are set in
// snapshot.
func isCoverageSubset(,  []byte) bool {
	for ,  := range  {
		if &[] !=  {
			return false
		}
	}
	return true
}

// hasCoverageBit returns true if snapshot has at least one bit set that is
// also set in base.
func hasCoverageBit(,  []byte) bool {
	for  := range  {
		if []&[] != 0 {
			return true
		}
	}
	return false
}

func countBits( []byte) int {
	 := 0
	for ,  := range  {
		 += bits.OnesCount8()
	}
	return 
}

var (
	coverageEnabled  = len(coverage()) > 0
	coverageSnapshot = make([]byte, len(coverage()))

	// _counters and _ecounters mark the start and end, respectively, of where
	// the 8-bit coverage counters reside in memory. They're known to cmd/link,
	// which specially assigns their addresses for this purpose.
	_counters, _ecounters [0]byte
)