xref: /titanic_44/usr/src/uts/sparc/ml/ip_ocsum.s (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate/*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate/*
23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gate#if defined(lint)
32*7c478bd9Sstevel@tonic-gate#include <sys/types.h>
33*7c478bd9Sstevel@tonic-gate#endif	/* lint */
34*7c478bd9Sstevel@tonic-gate
35*7c478bd9Sstevel@tonic-gate/*
36*7c478bd9Sstevel@tonic-gate * ip_ocsum(address, halfword_count, sum)
37*7c478bd9Sstevel@tonic-gate * Do a 16 bit one's complement sum of a given number of (16-bit)
38*7c478bd9Sstevel@tonic-gate * halfwords. The halfword pointer must not be odd.
39*7c478bd9Sstevel@tonic-gate *	%o0 address; %o1 count; %o2 sum accumulator; %o4 temp
40*7c478bd9Sstevel@tonic-gate * 	%g2 and %g3 used in main loop
41*7c478bd9Sstevel@tonic-gate *
42*7c478bd9Sstevel@tonic-gate * (from @(#)ocsum.s 1.3 89/02/24 SMI)
43*7c478bd9Sstevel@tonic-gate *
44*7c478bd9Sstevel@tonic-gate */
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gate#if defined(lint)
47*7c478bd9Sstevel@tonic-gate
48*7c478bd9Sstevel@tonic-gate/* ARGSUSED */
49*7c478bd9Sstevel@tonic-gateunsigned int
50*7c478bd9Sstevel@tonic-gateip_ocsum(u_short *address, int halfword_count, unsigned int sum)
51*7c478bd9Sstevel@tonic-gate{ return (0); }
52*7c478bd9Sstevel@tonic-gate
53*7c478bd9Sstevel@tonic-gate#else	/* lint */
54*7c478bd9Sstevel@tonic-gate
55*7c478bd9Sstevel@tonic-gate	ENTRY(ip_ocsum)
56*7c478bd9Sstevel@tonic-gate	cmp	%o1, 31		! less than 62 bytes?
57*7c478bd9Sstevel@tonic-gate	bl,a	.dohw		!   just do halfwords
58*7c478bd9Sstevel@tonic-gate	tst	%o1		! delay slot, test count
59*7c478bd9Sstevel@tonic-gate
60*7c478bd9Sstevel@tonic-gate	btst	31, %o0		! (delay slot)
61*7c478bd9Sstevel@tonic-gate	bz	2f		! if 32 byte aligned, skip
62*7c478bd9Sstevel@tonic-gate	nop
63*7c478bd9Sstevel@tonic-gate
64*7c478bd9Sstevel@tonic-gate	!
65*7c478bd9Sstevel@tonic-gate	! Do first halfwords until 32-byte aligned
66*7c478bd9Sstevel@tonic-gate	!
67*7c478bd9Sstevel@tonic-gate1:
68*7c478bd9Sstevel@tonic-gate	lduh	[%o0], %g2	! read data
69*7c478bd9Sstevel@tonic-gate	add	%o0, 2, %o0	! increment address
70*7c478bd9Sstevel@tonic-gate	add	%o2, %g2, %o2	! add to accumulator, don't need carry yet
71*7c478bd9Sstevel@tonic-gate	btst	31, %o0		! 32 byte aligned?
72*7c478bd9Sstevel@tonic-gate	bnz	1b
73*7c478bd9Sstevel@tonic-gate	sub	%o1, 1, %o1	! decrement count
74*7c478bd9Sstevel@tonic-gate	!
75*7c478bd9Sstevel@tonic-gate	! loop to add in 32 byte chunks
76*7c478bd9Sstevel@tonic-gate	! The loads and adds are staggered to help avoid load/use
77*7c478bd9Sstevel@tonic-gate	! interlocks on highly pipelined implementations, and double
78*7c478bd9Sstevel@tonic-gate	! loads are used for 64-bit wide memory systems.
79*7c478bd9Sstevel@tonic-gate	!
80*7c478bd9Sstevel@tonic-gate2:
81*7c478bd9Sstevel@tonic-gate	sub	%o1, 16, %o1	! decrement count to aid testing
82*7c478bd9Sstevel@tonic-gate4:
83*7c478bd9Sstevel@tonic-gate	ldd	[%o0], %g2	! read data
84*7c478bd9Sstevel@tonic-gate	ldd	[%o0+8], %o4	! read more data
85*7c478bd9Sstevel@tonic-gate	addcc	%o2, %g2, %o2	! add to accumulator
86*7c478bd9Sstevel@tonic-gate	addxcc	%o2, %g3, %o2	! add to accumulator with carry
87*7c478bd9Sstevel@tonic-gate	ldd	[%o0+16], %g2	! read more data
88*7c478bd9Sstevel@tonic-gate	addxcc	%o2, %o4, %o2	! add to accumulator with carry
89*7c478bd9Sstevel@tonic-gate	addxcc	%o2, %o5, %o2	! add to accumulator with carry
90*7c478bd9Sstevel@tonic-gate	ldd	[%o0+24], %o4	! read more data
91*7c478bd9Sstevel@tonic-gate	addxcc	%o2, %g2, %o2	! add to accumulator with carry
92*7c478bd9Sstevel@tonic-gate	addxcc	%o2, %g3, %o2	! add to accumulator with carry
93*7c478bd9Sstevel@tonic-gate	addxcc	%o2, %o4, %o2	! add to accumulator
94*7c478bd9Sstevel@tonic-gate	addxcc	%o2, %o5, %o2	! add to accumulator with carry
95*7c478bd9Sstevel@tonic-gate	addxcc	%o2, 0, %o2	! if final carry, add it in
96*7c478bd9Sstevel@tonic-gate	subcc	%o1, 16, %o1	! decrement count (in halfwords)
97*7c478bd9Sstevel@tonic-gate	bge	4b
98*7c478bd9Sstevel@tonic-gate	add	%o0, 32, %o0	! delay slot, increment address
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate	add	%o1, 16, %o1	! add back in
101*7c478bd9Sstevel@tonic-gate	!
102*7c478bd9Sstevel@tonic-gate	! Do any remaining halfwords
103*7c478bd9Sstevel@tonic-gate	!
104*7c478bd9Sstevel@tonic-gate	b	.dohw
105*7c478bd9Sstevel@tonic-gate	tst	%o1		! delay slot, for more to do
106*7c478bd9Sstevel@tonic-gate
107*7c478bd9Sstevel@tonic-gate3:
108*7c478bd9Sstevel@tonic-gate	add	%o0, 2, %o0	! increment address
109*7c478bd9Sstevel@tonic-gate	addcc	%o2, %g2, %o2	! add to accumulator
110*7c478bd9Sstevel@tonic-gate	addxcc	%o2, 0, %o2	! if carry, add it in
111*7c478bd9Sstevel@tonic-gate	subcc	%o1, 1, %o1	! decrement count
112*7c478bd9Sstevel@tonic-gate.dohw:
113*7c478bd9Sstevel@tonic-gate	bg,a	3b		! more to do?
114*7c478bd9Sstevel@tonic-gate	lduh	[%o0], %g2	! read data
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate	!
117*7c478bd9Sstevel@tonic-gate	! at this point the 32-bit accumulator
118*7c478bd9Sstevel@tonic-gate	! has the result that needs to be returned in 16-bits
119*7c478bd9Sstevel@tonic-gate	!
120*7c478bd9Sstevel@tonic-gate	sll	%o2, 16, %o4	! put low halfword in high halfword %o4
121*7c478bd9Sstevel@tonic-gate	addcc	%o4, %o2, %o2	! add the 2 halfwords in high %o2, set carry
122*7c478bd9Sstevel@tonic-gate	srl	%o2, 16, %o2	! shift to low halfword
123*7c478bd9Sstevel@tonic-gate	retl			! return
124*7c478bd9Sstevel@tonic-gate	addxcc	%o2, 0, %o0	! add in carry if any. result in %o0
125*7c478bd9Sstevel@tonic-gate	SET_SIZE(ip_ocsum)
126*7c478bd9Sstevel@tonic-gate
127*7c478bd9Sstevel@tonic-gate#endif 	/* lint */
128