mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* time.c (rb_big_abs_find_minbit): use ffs().
* configure.in: check ffs(). * missing/ffs.c: new file. * include/ruby/missing.h (ffs): declared. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									d80a859d98
								
							
						
					
					
						commit
						a00247f57a
					
				
					 5 changed files with 63 additions and 2 deletions
				
			
		
							
								
								
									
										47
									
								
								missing/ffs.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								missing/ffs.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,47 @@ | |||
| /* ffs.c - find first set bit */ | ||||
| /* ffs() is defined by POSIX. */ | ||||
| 
 | ||||
| #include "ruby.h" | ||||
| 
 | ||||
| int ffs(int arg) | ||||
| { | ||||
|     unsigned int x = (unsigned int)arg; | ||||
|     int r = 0; | ||||
| 
 | ||||
|     if (x == 0) | ||||
|         return 0; | ||||
| 
 | ||||
| #if 32 < SIZEOF_INT * CHAR_BIT | ||||
|     if ((x & 0xffffffff) == 0) { | ||||
|         x >>= 32; | ||||
|         r += 32; | ||||
|     } | ||||
| #endif | ||||
| 
 | ||||
|     if ((x & 0xffff) == 0) { | ||||
|         x >>= 16; | ||||
|         r += 16; | ||||
|     } | ||||
| 
 | ||||
|     if ((x & 0xff) == 0) { | ||||
|         x >>= 8; | ||||
|         r += 8; | ||||
|     } | ||||
| 
 | ||||
|     if ((x & 0xf) == 0) { | ||||
|         x >>= 4; | ||||
|         r += 4; | ||||
|     } | ||||
| 
 | ||||
|     if ((x & 0x3) == 0) { | ||||
|         x >>= 2; | ||||
|         r += 2; | ||||
|     } | ||||
| 
 | ||||
|     if ((x & 0x1) == 0) { | ||||
|         x >>= 1; | ||||
|         r += 1; | ||||
|     } | ||||
| 
 | ||||
|     return r; | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 akr
						akr