\ ========== Copyright Header Begin ==========================================
\ Hypervisor Software File: divrem.fth
\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
\ - Do no alter or remove copyright notices
\ - Redistribution and use of this software in source and binary forms, with
\ or without modification, are permitted provided that the following
\ - Redistribution of source code must retain the above copyright notice,
\ this list of conditions and the following disclaimer.
\ - Redistribution in binary form must reproduce the above copyright notice,
\ this list of conditions and the following disclaimer in the
\ documentation and/or other materials provided with the distribution.
\ Neither the name of Sun Microsystems, Inc. or the names of contributors
\ may be used to endorse or promote products derived from this software
\ without specific prior written permission.
\ This software is provided "AS IS," without a warranty of any kind.
\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
\ You acknowledge that this software is not designed, licensed or
\ intended for use in the design, construction, operation or maintenance of
\ ========== Copyright Header End ============================================
id: @(#)divrem.fth 1.5 96/03/01
copyright: Copyright 1992 Sun Microsystems, Inc. All Rights Reserved
\ Translated directly from forthlang/kernel/sparc/divrem.s
\ It generates exactly the same code as divrem.s
code u/mod (s u.dividend u.divisor -- u.remainder u.quotient )
sp 0 /n* sc6 nget \ dividend in %l6
%g0 tos sc1 add \ divisor in %l1
u>= if %g0 %g0 %l0 or ( Delay slot )
0 F: u>= brif %g0 1 %l4 or ( Delay slot )
u< if %l4 1 %l4 add ( Delay slot )
1 F: bra %l4 1 %l4 sub ( Delay slot )
u>= until nop ( Delay slot )
<> if nop then \ XXXX Don't really need this !!!
3 F: < brif nop ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
2 F: bra %l5 1 %l5 add ( Delay slot )
< until %g0 %l6 %g0 orcc ( Delay slot )
u> until %l0 1 %l0 addcc ( Delay slot )
<> if %l0 1 %l0 sub ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
3 F: bra %l5 h# 0f %l5 add ( Delay slot )
3 F: bra %l5 h# 0d %l5 add ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
3 F: bra %l5 h# 0b %l5 add ( Delay slot )
3 F: bra %l5 h# 09 %l5 add ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
3 F: bra %l5 h# 07 %l5 add ( Delay slot )
3 F: bra %l5 h# 05 %l5 add ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
3 F: bra %l5 h# 03 %l5 add ( Delay slot )
3 F: bra %l5 h# 01 %l5 add ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
3 F: bra %l5 h# -1 %l5 add ( Delay slot )
3 F: bra %l5 h# -3 %l5 add ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
3 F: bra %l5 h# -5 %l5 add ( Delay slot )
3 F: bra %l5 h# -7 %l5 add ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
3 F: bra %l5 h# -9 %l5 add ( Delay slot )
3 F: bra %l5 h# -0b %l5 add ( Delay slot )
>= if %l1 1 %l1 srln ( Delay slot )
3 F: bra %l5 h# -0d %l5 add ( Delay slot )
\ XXXX Don't really need the following 3 F: bra !!!
3 F: bra %l5 h# -0f %l5 add ( Delay slot )
< until %g0 %l6 %g0 orcc ( Delay slot )
nop \ XXXX Don't really need this !!!
sc6 sp 0 /n* nput \ remainder
%g0 sc5 tos add \ quotient