1*ae3cb403Sguenther/* $OpenBSD: ffs.S,v 1.4 2018/01/18 08:23:44 guenther Exp $ */ 239bae441Sniklas/* $NetBSD: ffs.S,v 1.3 1996/10/17 03:08:13 cgd Exp $ */ 339bae441Sniklas 439bae441Sniklas/* 539bae441Sniklas * Copyright (c) 1995 Christopher G. Demetriou 639bae441Sniklas * All rights reserved. 739bae441Sniklas * 839bae441Sniklas * Redistribution and use in source and binary forms, with or without 939bae441Sniklas * modification, are permitted provided that the following conditions 1039bae441Sniklas * are met: 1139bae441Sniklas * 1. Redistributions of source code must retain the above copyright 1239bae441Sniklas * notice, this list of conditions and the following disclaimer. 1339bae441Sniklas * 2. Redistributions in binary form must reproduce the above copyright 1439bae441Sniklas * notice, this list of conditions and the following disclaimer in the 1539bae441Sniklas * documentation and/or other materials provided with the distribution. 1639bae441Sniklas * 3. All advertising materials mentioning features or use of this software 1739bae441Sniklas * must display the following acknowledgement: 1839bae441Sniklas * This product includes software developed by Christopher G. Demetriou 1939bae441Sniklas * for the NetBSD Project. 2039bae441Sniklas * 4. The name of the author may not be used to endorse or promote products 2139bae441Sniklas * derived from this software without specific prior written permission 2239bae441Sniklas * 2339bae441Sniklas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2439bae441Sniklas * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2539bae441Sniklas * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2639bae441Sniklas * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2739bae441Sniklas * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2839bae441Sniklas * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2939bae441Sniklas * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3039bae441Sniklas * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3139bae441Sniklas * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3239bae441Sniklas * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3339bae441Sniklas */ 3439bae441Sniklas 359b9d2a55Sguenther#include "SYS.h" 3639bae441Sniklas 3739bae441SniklasLEAF(ffs, 1) 3839bae441Sniklas addl a0, 0, t0 3939bae441Sniklas beq t0, Lallzero 4039bae441Sniklas 4139bae441Sniklas /* 4239bae441Sniklas * Initialize return value (v0), and set up t1 so that it 4339bae441Sniklas * contains the mask with only the lowest bit set. 4439bae441Sniklas */ 4539bae441Sniklas subl zero, t0, t1 4639bae441Sniklas ldil v0, 1 4739bae441Sniklas and t0, t1, t1 4839bae441Sniklas 4939bae441Sniklas and t1, 0xff, t2 5039bae441Sniklas bne t2, Ldo8 5139bae441Sniklas 5239bae441Sniklas /* 5339bae441Sniklas * If lower 16 bits empty, add 16 to result and use upper 16. 5439bae441Sniklas */ 5539bae441Sniklas zapnot t1, 0x03, t3 5639bae441Sniklas bne t3, Ldo16 5739bae441Sniklas sra t1, 16, t1 5839bae441Sniklas addl v0, 16, v0 5939bae441Sniklas 6039bae441SniklasLdo16: 6139bae441Sniklas /* 6239bae441Sniklas * If lower 8 bits empty, add 8 to result and use upper 8. 6339bae441Sniklas */ 6439bae441Sniklas and t1, 0xff, t4 6539bae441Sniklas bne t4, Ldo8 6639bae441Sniklas sra t1, 8, t1 6739bae441Sniklas addl v0, 8, v0 6839bae441Sniklas 6939bae441SniklasLdo8: 7039bae441Sniklas and t1, 0x0f, t5 /* lower 4 of 8 empty? */ 7139bae441Sniklas and t1, 0x33, t6 /* lower 2 of each 4 empty? */ 7239bae441Sniklas and t1, 0x55, t7 /* lower 1 of each 2 empty? */ 7339bae441Sniklas 7439bae441Sniklas /* If lower 4 bits empty, add 4 to result. */ 7539bae441Sniklas bne t5, Ldo4 7639bae441Sniklas addl v0, 4, v0 7739bae441Sniklas 7839bae441SniklasLdo4: /* If lower 2 bits of each 4 empty, add 2 to result. */ 7939bae441Sniklas bne t6, Ldo2 8039bae441Sniklas addl v0, 2, v0 8139bae441Sniklas 8239bae441SniklasLdo2: /* If lower bit of each 2 empty, add 1 to result. */ 8339bae441Sniklas bne t7, Ldone 8439bae441Sniklas addl v0, 1, v0 8539bae441Sniklas 8639bae441SniklasLdone: 8739bae441Sniklas RET 8839bae441Sniklas 8939bae441SniklasLallzero: 9039bae441Sniklas bis zero, zero, v0 9139bae441Sniklas RET 92*ae3cb403SguentherEND(ffs) 93*ae3cb403Sguenther.protected ffs 94