1b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand/* libs/opengles/arch-mips/fixed_asm.S 2b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** 3b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** Copyright 2012, The Android Open Source Project 4b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** 5b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** Licensed under the Apache License, Version 2.0 (the "License"); 6b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** you may not use this file except in compliance with the License. 7b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** You may obtain a copy of the License at 8b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** 9b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** http://www.apache.org/licenses/LICENSE-2.0 10b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** 11b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** Unless required by applicable law or agreed to in writing, software 12b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** distributed under the License is distributed on an "AS IS" BASIS, 13b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** See the License for the specific language governing permissions and 15b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand** limitations under the License. 16b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand*/ 17b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand 18b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand 19b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand .text 20b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand .align 21b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand 22b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand/* 23b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand * this version rounds-to-nearest and saturates numbers 24b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand * outside the range (but not NaNs). 25b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand */ 26b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand 27b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand .global gglFloatToFixed 28b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand .ent gglFloatToFixed 29b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand .type gglFloatToFixed, @function 30b43722c3dd69a90f0d0665912bd543aa12521c58Duane SandgglFloatToFixed: 31b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand#if !defined(__mips_soft_float) 32b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand mfc1 $a0,$f12 33b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand#endif 34b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand srl $t0,$a0,31 /* t0 <- sign bit */ 35b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand srl $t1,$a0,23 36b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand andi $t1,$t1,0xff /* get the e */ 37b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand li $t2,0x8e 38b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand subu $t1,$t2,$t1 /* t1=127+15-e */ 39b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand blez $t1,0f /* t1<=0? */ 40b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand sll $t2,$a0,8 /* mantissa<<8 */ 41b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand lui $t3,0x8000 42b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand or $t2,$t2,$t3 /* add the missing 1 */ 43b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand subu $t1,$t1,1 44b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand srl $v0,$t2,$t1 45b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand sltiu $t3,$t1,32 /* t3=1 if t1<32, else t3=0. t1>=32 means the float value is too small. */ 46b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand andi $t4,$v0,0x1 47b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand srl $v0,$v0,1 /* scale to 16.16 */ 48b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand addu $v0,$v0,$t4 /* round-to-nearest */ 49b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand subu $t2,$zero,$v0 50b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand movn $v0,$t2,$t0 /* if negative? */ 51b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand or $t1,$a0,$zero /* a0=0? */ 52b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand movz $v0,$zero,$t1 53b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand movz $v0,$zero,$t3 /* t3=0 then res=0 */ 54b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand jr $ra 55b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand0: 56b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand lui $t1,0x8000 57b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand and $v0,$a0,$t1 /* keep only the sign bit */ 58b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand li $t1,0x7fffffff 59b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand movz $v0,$t1,$t0 /* positive, maximum value */ 60b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand jr $ra 61b43722c3dd69a90f0d0665912bd543aa12521c58Duane Sand .end gglFloatToFixed 62