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