mirror of
				https://github.com/golang/go.git
				synced 2025-10-31 08:40:55 +00:00 
			
		
		
		
	[dev.garbage] runtime: use sys.Ctz64 intrinsic
Our compilers now provides instrinsics including sys.Ctz64 that support CTZ (count trailing zero) instructions. This CL replaces the Go versions of CTZ with the compiler intrinsic. Count trailing zeros CTZ finds the least significant 1 in a word and returns the number of less significant 0s in the word. Allocation uses the bitmap created by the garbage collector to locate an unmarked object. The logic takes a word of the bitmap, complements, and then caches it. It then uses CTZ to locate an available unmarked object. It then shifts marked bits out of the bitmap word preparing it for the next search. Once all the unmarked objects are used in the cached work the bitmap gets another word and repeats the process. Change-Id: Id2fc42d1d4b9893efaa2e1bd01896985b7e42f82 Reviewed-on: https://go-review.googlesource.com/21366 Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
		
							parent
							
								
									2063d5d903
								
							
						
					
					
						commit
						2fb75ea6c6
					
				
					 3 changed files with 12 additions and 66 deletions
				
			
		|  | @ -491,14 +491,13 @@ var zerobase uintptr | |||
| // Otherwise it returns 0. | ||||
| func (c *mcache) nextFreeFast(sizeclass int8) gclinkptr { | ||||
| 	s := c.alloc[sizeclass] | ||||
| 	ctzIndex := uint8(s.allocCache) | ||||
| 	if ctzIndex != 0 { | ||||
| 		theBit := uint64(ctzVals[ctzIndex]) | ||||
| 		freeidx := s.freeindex // help the pre ssa compiler out here with cse. | ||||
| 		result := freeidx + uintptr(theBit) | ||||
| 
 | ||||
| 	theBit := sys.Ctz64(s.allocCache) // Is there a free object in the allocCache? | ||||
| 	if theBit < 64 { | ||||
| 		result := s.freeindex + uintptr(theBit) | ||||
| 		if result < s.nelems { | ||||
| 			s.allocCache >>= (theBit + 1) | ||||
| 			freeidx = result + 1 | ||||
| 			freeidx := result + 1 | ||||
| 			if freeidx%64 == 0 && freeidx != s.nelems { | ||||
| 				// We just incremented s.freeindex so it isn't 0 | ||||
| 				// so we are moving to the next aCache. | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Rick Hudson
						Rick Hudson