brintos

brintos / linux-shallow public Read only

0
0
Text · 2.6 KiB · 214a6d9 Raw
95 lines · plain
1/*2 * Copyright 2014 Martin Peres <martin.peres@free.fr>3 *4 * Permission is hereby granted, free of charge, to any person obtaining a5 * copy of this software and associated documentation files (the "Software"),6 * to deal in the Software without restriction, including without limitation7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,8 * and/or sell copies of the Software, and to permit persons to whom the9 * Software is furnished to do so, subject to the folloing conditions:10 *11 * The above copyright notice and this permission notice shall be included in12 * all copies or substantial portions of the Software.13 *14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR20 * OTHER DEALINGS IN THE SOFTWARE.21 *22 * Authors: Martin Peres23 */24 25/******************************************************************************26 * arith data segment27 *****************************************************************************/28#ifdef INCLUDE_PROC29#endif30 31#ifdef INCLUDE_DATA32#endif33 34/******************************************************************************35 * arith code segment36 *****************************************************************************/37#ifdef INCLUDE_CODE38 39// does a 32x32 -> 64 multiplication40//41// A * B = A_lo * B_lo42//        + ( A_hi * B_lo ) << 1643//        + ( A_lo * B_hi ) << 1644//        + ( A_hi * B_hi ) << 3245//46// $r15 - current47// $r14 - A48// $r13 - B49// $r12 - mul_lo (return)50// $r11 - mul_hi (return)51// $r0  - zero52mulu32_32_64:53	push $r1 // A_hi54	push $r2 // B_hi55	push $r3 // tmp056	push $r4 // tmp157 58	shr b32 $r1 $r14 1659	shr b32 $r2 $r13 1660 61	clear b32 $r1262	clear b32 $r1163 64	// A_lo * B_lo65	mulu $r12 $r14 $r1366 67	// ( A_hi * B_lo ) << 1668	mulu $r3 $r1 $r13 // tmp0 = A_hi * B_lo69	mov b32 $r4 $r370	and $r3 0xffff // tmp0 = tmp0_lo71	shl b32 $r3 1672	shr b32 $r4 16 // tmp1 = tmp0_hi73	add b32 $r12 $r374	adc b32 $r11 $r475 76	// ( A_lo * B_hi ) << 1677	mulu $r3 $r14 $r2 // tmp0 = A_lo * B_hi78	mov b32 $r4 $r379	and $r3 0xffff // tmp0 = tmp0_lo80	shl b32 $r3 1681	shr b32 $r4 16 // tmp1 = tmp0_hi82	add b32 $r12 $r383	adc b32 $r11 $r484 85	// ( A_hi * B_hi ) << 3286	mulu $r3 $r1 $r2 // tmp0 = A_hi * B_hi87	add b32 $r11 $r388 89	pop $r490	pop $r391	pop $r292	pop $r193	ret94#endif95