Blame thirdparty/openblas/xianyi-OpenBLAS-e6e87a2/driver/level3/gemm3m_level3.c

kusano 2b45e8
/*********************************************************************/
kusano 2b45e8
/* Copyright 2009, 2010 The University of Texas at Austin.           */
kusano 2b45e8
/* All rights reserved.                                              */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/* Redistribution and use in source and binary forms, with or        */
kusano 2b45e8
/* without modification, are permitted provided that the following   */
kusano 2b45e8
/* conditions are met:                                               */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*   1. Redistributions of source code must retain the above         */
kusano 2b45e8
/*      copyright notice, this list of conditions and the following  */
kusano 2b45e8
/*      disclaimer.                                                  */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*   2. Redistributions in binary form must reproduce the above      */
kusano 2b45e8
/*      copyright notice, this list of conditions and the following  */
kusano 2b45e8
/*      disclaimer in the documentation and/or other materials       */
kusano 2b45e8
/*      provided with the distribution.                              */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
kusano 2b45e8
/*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
kusano 2b45e8
/*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
kusano 2b45e8
/*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
kusano 2b45e8
/*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
kusano 2b45e8
/*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
kusano 2b45e8
/*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
kusano 2b45e8
/*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
kusano 2b45e8
/*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
kusano 2b45e8
/*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
kusano 2b45e8
/*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
kusano 2b45e8
/*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
kusano 2b45e8
/*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
kusano 2b45e8
/*    POSSIBILITY OF SUCH DAMAGE.                                    */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/* The views and conclusions contained in the software and           */
kusano 2b45e8
/* documentation are those of the authors and should not be          */
kusano 2b45e8
/* interpreted as representing official policies, either expressed   */
kusano 2b45e8
/* or implied, of The University of Texas at Austin.                 */
kusano 2b45e8
/*********************************************************************/
kusano 2b45e8
kusano 2b45e8
#include <stdio.h></stdio.h>
kusano 2b45e8
#include "common.h"
kusano 2b45e8
kusano 2b45e8
#ifndef BETA_OPERATION
kusano 2b45e8
#define BETA_OPERATION(M_FROM, M_TO, N_FROM, N_TO, BETA, C, LDC) \
kusano 2b45e8
	GEMM_BETA((M_TO) - (M_FROM), (N_TO - N_FROM), 0, \
kusano 2b45e8
		  BETA[0], BETA[1], NULL, 0, NULL, 0, \
kusano 2b45e8
		  (FLOAT *)(C) + (M_FROM) + (N_FROM) * (LDC) * COMPSIZE, LDC)
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifndef ICOPYB_OPERATION
kusano 2b45e8
#if defined(NN) || defined(NT) || defined(NC) || defined(NR) || \
kusano 2b45e8
    defined(RN) || defined(RT) || defined(RC) || defined(RR)
kusano 2b45e8
#define ICOPYB_OPERATION(M, N, A, LDA, X, Y, BUFFER) \
kusano 2b45e8
	GEMM3M_ITCOPYB(M, N, (FLOAT *)(A) + ((Y) + (X) * (LDA)) * COMPSIZE, LDA, BUFFER)
kusano 2b45e8
#else
kusano 2b45e8
#define ICOPYB_OPERATION(M, N, A, LDA, X, Y, BUFFER) \
kusano 2b45e8
	GEMM3M_INCOPYB(M, N, (FLOAT *)(A) + ((X) + (Y) * (LDA)) * COMPSIZE, LDA, BUFFER)
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifndef ICOPYR_OPERATION
kusano 2b45e8
#if defined(NN) || defined(NT) || defined(NC) || defined(NR) || \
kusano 2b45e8
    defined(RN) || defined(RT) || defined(RC) || defined(RR)
kusano 2b45e8
#define ICOPYR_OPERATION(M, N, A, LDA, X, Y, BUFFER) \
kusano 2b45e8
	GEMM3M_ITCOPYR(M, N, (FLOAT *)(A) + ((Y) + (X) * (LDA)) * COMPSIZE, LDA, BUFFER)
kusano 2b45e8
#else
kusano 2b45e8
#define ICOPYR_OPERATION(M, N, A, LDA, X, Y, BUFFER) \
kusano 2b45e8
	GEMM3M_INCOPYR(M, N, (FLOAT *)(A) + ((X) + (Y) * (LDA)) * COMPSIZE, LDA, BUFFER)
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifndef ICOPYI_OPERATION
kusano 2b45e8
#if defined(NN) || defined(NT) || defined(NC) || defined(NR) || \
kusano 2b45e8
    defined(RN) || defined(RT) || defined(RC) || defined(RR)
kusano 2b45e8
#define ICOPYI_OPERATION(M, N, A, LDA, X, Y, BUFFER) \
kusano 2b45e8
	GEMM3M_ITCOPYI(M, N, (FLOAT *)(A) + ((Y) + (X) * (LDA)) * COMPSIZE, LDA, BUFFER)
kusano 2b45e8
#else
kusano 2b45e8
#define ICOPYI_OPERATION(M, N, A, LDA, X, Y, BUFFER) \
kusano 2b45e8
	GEMM3M_INCOPYI(M, N, (FLOAT *)(A) + ((X) + (Y) * (LDA)) * COMPSIZE, LDA, BUFFER)
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
#ifndef OCOPYB_OPERATION
kusano 2b45e8
#if defined(NN) || defined(TN) || defined(CN) || defined(RN) || \
kusano 2b45e8
    defined(NR) || defined(TR) || defined(CR) || defined(RR)
kusano 2b45e8
#define OCOPYB_OPERATION(M, N, A, LDA, ALPHA_R, ALPHA_I, X, Y, BUFFER) \
kusano 2b45e8
	GEMM3M_ONCOPYB(M, N, (FLOAT *)(A) + ((X) + (Y) * (LDA)) * COMPSIZE, LDA, ALPHA_R, ALPHA_I, BUFFER)
kusano 2b45e8
#else
kusano 2b45e8
#define OCOPYB_OPERATION(M, N, A, LDA, ALPHA_R, ALPHA_I, X, Y, BUFFER) \
kusano 2b45e8
	GEMM3M_OTCOPYB(M, N, (FLOAT *)(A) + ((Y) + (X) * (LDA)) * COMPSIZE, LDA, ALPHA_R, ALPHA_I, BUFFER)
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifndef OCOPYR_OPERATION
kusano 2b45e8
#if defined(NN) || defined(TN) || defined(CN) || defined(RN) || \
kusano 2b45e8
    defined(NR) || defined(TR) || defined(CR) || defined(RR)
kusano 2b45e8
#define OCOPYR_OPERATION(M, N, A, LDA, ALPHA_R, ALPHA_I, X, Y, BUFFER) \
kusano 2b45e8
	GEMM3M_ONCOPYR(M, N, (FLOAT *)(A) + ((X) + (Y) * (LDA)) * COMPSIZE, LDA, ALPHA_R, ALPHA_I, BUFFER)
kusano 2b45e8
#else
kusano 2b45e8
#define OCOPYR_OPERATION(M, N, A, LDA, ALPHA_R, ALPHA_I, X, Y, BUFFER) \
kusano 2b45e8
	GEMM3M_OTCOPYR(M, N, (FLOAT *)(A) + ((Y) + (X) * (LDA)) * COMPSIZE, LDA, ALPHA_R, ALPHA_I, BUFFER)
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
#ifndef OCOPYI_OPERATION
kusano 2b45e8
#if defined(NN) || defined(TN) || defined(CN) || defined(RN) || \
kusano 2b45e8
    defined(NR) || defined(TR) || defined(CR) || defined(RR)
kusano 2b45e8
#define OCOPYI_OPERATION(M, N, A, LDA, ALPHA_R, ALPHA_I, X, Y, BUFFER) \
kusano 2b45e8
	GEMM3M_ONCOPYI(M, N, (FLOAT *)(A) + ((X) + (Y) * (LDA)) * COMPSIZE, LDA, ALPHA_R, ALPHA_I, BUFFER)
kusano 2b45e8
#else
kusano 2b45e8
#define OCOPYI_OPERATION(M, N, A, LDA, ALPHA_R, ALPHA_I, X, Y, BUFFER) \
kusano 2b45e8
	GEMM3M_OTCOPYI(M, N, (FLOAT *)(A) + ((Y) + (X) * (LDA)) * COMPSIZE, LDA, ALPHA_R, ALPHA_I, BUFFER)
kusano 2b45e8
#endif
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifndef KERNEL_FUNC
kusano 2b45e8
#define KERNEL_FUNC	GEMM3M_KERNEL
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifndef KERNEL_OPERATION
kusano 2b45e8
#define KERNEL_OPERATION(M, N, K, ALPHA_R, ALPHA_I, SA, SB, C, LDC, X, Y) \
kusano 2b45e8
	KERNEL_FUNC(M, N, K, ALPHA_R, ALPHA_I, SA, SB, (FLOAT *)(C) + ((X) + (Y) * LDC) * COMPSIZE, LDC)
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifndef A
kusano 2b45e8
#define A	args -> a
kusano 2b45e8
#endif
kusano 2b45e8
#ifndef LDA
kusano 2b45e8
#define LDA	args -> lda
kusano 2b45e8
#endif
kusano 2b45e8
#ifndef B
kusano 2b45e8
#define B	args -> b
kusano 2b45e8
#endif
kusano 2b45e8
#ifndef LDB
kusano 2b45e8
#define LDB	args -> ldb
kusano 2b45e8
#endif
kusano 2b45e8
#ifndef C
kusano 2b45e8
#define C	args -> c
kusano 2b45e8
#endif
kusano 2b45e8
#ifndef LDC
kusano 2b45e8
#define LDC	args -> ldc
kusano 2b45e8
#endif
kusano 2b45e8
#ifndef M
kusano 2b45e8
#define M	args -> m
kusano 2b45e8
#endif
kusano 2b45e8
#ifndef N
kusano 2b45e8
#define N	args -> n
kusano 2b45e8
#endif
kusano 2b45e8
#ifndef K
kusano 2b45e8
#define K	args -> k
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#if defined(NN) || defined(NT) || defined(TN) || defined(TT)
kusano 2b45e8
#define ALPHA1	ONE
kusano 2b45e8
#define ALPHA2	ONE
kusano 2b45e8
#define ALPHA5	ZERO
kusano 2b45e8
#define ALPHA6	ONE
kusano 2b45e8
kusano 2b45e8
#define ALPHA7	ONE
kusano 2b45e8
#define ALPHA8	ZERO
kusano 2b45e8
#define ALPHA11	ONE
kusano 2b45e8
#define ALPHA12	-ONE
kusano 2b45e8
kusano 2b45e8
#define ALPHA13	ZERO
kusano 2b45e8
#define ALPHA14	ONE
kusano 2b45e8
#define ALPHA17	-ONE
kusano 2b45e8
#define ALPHA18	-ONE
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#if defined(NR) || defined(NC) || defined(TR) || defined(TC)
kusano 2b45e8
#define ALPHA1	ONE
kusano 2b45e8
#define ALPHA2	ONE
kusano 2b45e8
#define ALPHA5	ONE
kusano 2b45e8
#define ALPHA6	ZERO
kusano 2b45e8
kusano 2b45e8
#define ALPHA7	ZERO
kusano 2b45e8
#define ALPHA8	ONE
kusano 2b45e8
#define ALPHA11	-ONE
kusano 2b45e8
#define ALPHA12	-ONE
kusano 2b45e8
kusano 2b45e8
#define ALPHA13	ONE
kusano 2b45e8
#define ALPHA14	ZERO
kusano 2b45e8
#define ALPHA17	-ONE
kusano 2b45e8
#define ALPHA18	ONE
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#if defined(RN) || defined(RT) || defined(CN) || defined(CT)
kusano 2b45e8
#define ALPHA1	ONE
kusano 2b45e8
#define ALPHA2	ONE
kusano 2b45e8
#define ALPHA5	ONE
kusano 2b45e8
#define ALPHA6	ZERO
kusano 2b45e8
kusano 2b45e8
#define ALPHA7	ZERO
kusano 2b45e8
#define ALPHA8	ONE
kusano 2b45e8
#define ALPHA11	-ONE
kusano 2b45e8
#define ALPHA12	ONE
kusano 2b45e8
kusano 2b45e8
#define ALPHA13	ONE
kusano 2b45e8
#define ALPHA14	ZERO
kusano 2b45e8
#define ALPHA17	-ONE
kusano 2b45e8
#define ALPHA18	-ONE
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#if defined(RR) || defined(RC) || defined(CR) || defined(CC)
kusano 2b45e8
#define ALPHA1	ONE
kusano 2b45e8
#define ALPHA2	ONE
kusano 2b45e8
#define ALPHA5	ZERO
kusano 2b45e8
#define ALPHA6	-ONE
kusano 2b45e8
kusano 2b45e8
#define ALPHA7	ONE
kusano 2b45e8
#define ALPHA8	ZERO
kusano 2b45e8
#define ALPHA11	ONE
kusano 2b45e8
#define ALPHA12	ONE
kusano 2b45e8
kusano 2b45e8
#define ALPHA13	ZERO
kusano 2b45e8
#define ALPHA14	ONE
kusano 2b45e8
#define ALPHA17	-ONE
kusano 2b45e8
#define ALPHA18	ONE
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifdef TIMING
kusano 2b45e8
#define START_RPCC()		rpcc_counter = rpcc()
kusano 2b45e8
#define STOP_RPCC(COUNTER)	COUNTER  += rpcc() - rpcc_counter
kusano 2b45e8
#else
kusano 2b45e8
#define START_RPCC()
kusano 2b45e8
#define STOP_RPCC(COUNTER)
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
int CNAME(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n,
kusano 2b45e8
		  FLOAT *sa, FLOAT *sb, BLASLONG dummy){
kusano 2b45e8
  BLASLONG k, lda, ldb, ldc;
kusano 2b45e8
  FLOAT *alpha, *beta;
kusano 2b45e8
  FLOAT *a, *b, *c;
kusano 2b45e8
  BLASLONG m_from, m_to, n_from, n_to;
kusano 2b45e8
kusano 2b45e8
  BLASLONG ls, is, js, jjs;
kusano 2b45e8
  BLASLONG min_l, min_i, min_j, min_jj;
kusano 2b45e8
kusano 2b45e8
#ifdef TIMING
kusano 2b45e8
  BLASULONG rpcc_counter;
kusano 2b45e8
  BLASULONG BLASLONG innercost  = 0;
kusano 2b45e8
  BLASULONG BLASLONG outercost  = 0;
kusano 2b45e8
  BLASULONG BLASLONG kernelcost = 0;
kusano 2b45e8
  double total;
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
  k = K;
kusano 2b45e8
kusano 2b45e8
  a = (FLOAT *)A;
kusano 2b45e8
  b = (FLOAT *)B;
kusano 2b45e8
  c = (FLOAT *)C;
kusano 2b45e8
kusano 2b45e8
  lda = LDA;
kusano 2b45e8
  ldb = LDB;
kusano 2b45e8
  ldc = LDC;
kusano 2b45e8
kusano 2b45e8
  alpha = (FLOAT *)args -> alpha;
kusano 2b45e8
  beta  = (FLOAT *)args -> beta;
kusano 2b45e8
kusano 2b45e8
  m_from = 0;
kusano 2b45e8
  m_to   = M;
kusano 2b45e8
kusano 2b45e8
  if (range_m) {
kusano 2b45e8
    m_from = *(((BLASLONG *)range_m) + 0);
kusano 2b45e8
    m_to   = *(((BLASLONG *)range_m) + 1);
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  n_from = 0;
kusano 2b45e8
  n_to   = N;
kusano 2b45e8
kusano 2b45e8
  if (range_n) {
kusano 2b45e8
    n_from = *(((BLASLONG *)range_n) + 0);
kusano 2b45e8
    n_to   = *(((BLASLONG *)range_n) + 1);
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (beta) {
kusano 2b45e8
#ifndef COMPLEX
kusano 2b45e8
    if (beta[0] != ONE)
kusano 2b45e8
#else
kusano 2b45e8
    if ((beta[0] != ONE) || (beta[1] != ZERO))
kusano 2b45e8
#endif
kusano 2b45e8
      BETA_OPERATION(m_from, m_to, n_from, n_to, beta, c, ldc);
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if ((k == 0) || (alpha == NULL)) return 0;
kusano 2b45e8
kusano 2b45e8
  if ((alpha[0] == ZERO)
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
      && (alpha[1] == ZERO)
kusano 2b45e8
#endif
kusano 2b45e8
      ) return 0;
kusano 2b45e8
kusano 2b45e8
#if 0
kusano 2b45e8
  printf("GEMM: M_from : %ld  M_to : %ld  N_from : %ld  N_to : %ld  k : %ld\n", m_from, m_to, n_from, n_to, k);
kusano 2b45e8
  printf("GEMM: P = %4ld  Q = %4ld  R = %4ld\n", (BLASLONG)GEMM3M_P, (BLASLONG)GEMM3M_Q, (BLASLONG)GEMM3M_R);
kusano 2b45e8
  printf("GEMM: SA .. %p  SB .. %p\n", sa, sb);
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifdef TIMING
kusano 2b45e8
  innercost = 0;
kusano 2b45e8
  outercost = 0;
kusano 2b45e8
  kernelcost = 0;
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
  for(js = n_from; js < n_to; js += GEMM3M_R){
kusano 2b45e8
    min_j = n_to - js;
kusano 2b45e8
    if (min_j > GEMM3M_R) min_j = GEMM3M_R;
kusano 2b45e8
    
kusano 2b45e8
    for(ls = 0; ls < k; ls += min_l){
kusano 2b45e8
      min_l = k - ls;
kusano 2b45e8
      
kusano 2b45e8
      if (min_l >= GEMM3M_Q * 2) {
kusano 2b45e8
	min_l = GEMM3M_Q;
kusano 2b45e8
      } else {
kusano 2b45e8
	if (min_l > GEMM3M_Q) {
kusano 2b45e8
	  min_l = (min_l + 1) / 2;
kusano 2b45e8
#ifdef UNROLL_X
kusano 2b45e8
	  min_l = (min_l + UNROLL_X - 1) & ~(UNROLL_X - 1);
kusano 2b45e8
#endif
kusano 2b45e8
	}
kusano 2b45e8
      }
kusano 2b45e8
      
kusano 2b45e8
      min_i = m_to - m_from;
kusano 2b45e8
      if (min_i >= GEMM3M_P * 2) {
kusano 2b45e8
	min_i = GEMM3M_P;
kusano 2b45e8
      } else {
kusano 2b45e8
	if (min_i > GEMM3M_P) {
kusano 2b45e8
	  min_i = (min_i / 2 + GEMM3M_UNROLL_M - 1) & ~(GEMM3M_UNROLL_M - 1);
kusano 2b45e8
	}
kusano 2b45e8
      }
kusano 2b45e8
kusano 2b45e8
      START_RPCC();
kusano 2b45e8
      
kusano 2b45e8
      ICOPYB_OPERATION(min_l, min_i, a, lda, ls, m_from, sa);
kusano 2b45e8
      
kusano 2b45e8
      STOP_RPCC(innercost);
kusano 2b45e8
      
kusano 2b45e8
      for(jjs = js; jjs < js + min_j; jjs += min_jj){
kusano 2b45e8
	min_jj = min_j + js - jjs;
kusano 2b45e8
	if (min_jj > GEMM3M_UNROLL_N) min_jj = GEMM3M_UNROLL_N;
kusano 2b45e8
	
kusano 2b45e8
	START_RPCC();
kusano 2b45e8
	
kusano 2b45e8
#if defined(NN) || defined(NT) || defined(TN) || defined(TT) || defined(RN) || defined(RT) || defined(CN) || defined(CT)
kusano 2b45e8
	OCOPYB_OPERATION(min_l, min_jj, b, ldb, alpha[0],  alpha[1], ls, jjs, sb + min_l * (jjs - js));
kusano 2b45e8
#else
kusano 2b45e8
	OCOPYB_OPERATION(min_l, min_jj, b, ldb, alpha[0], -alpha[1], ls, jjs, sb + min_l * (jjs - js));
kusano 2b45e8
#endif
kusano 2b45e8
	
kusano 2b45e8
	STOP_RPCC(outercost);
kusano 2b45e8
	
kusano 2b45e8
	START_RPCC();
kusano 2b45e8
	
kusano 2b45e8
	KERNEL_OPERATION(min_i, min_jj, min_l, ALPHA5, ALPHA6,
kusano 2b45e8
			 sa, sb + min_l * (jjs - js), c, ldc, m_from, jjs);
kusano 2b45e8
	
kusano 2b45e8
	STOP_RPCC(kernelcost);
kusano 2b45e8
	
kusano 2b45e8
      }      
kusano 2b45e8
      
kusano 2b45e8
      for(is = m_from + min_i; is < m_to; is += min_i){
kusano 2b45e8
	min_i = m_to - is;
kusano 2b45e8
	if (min_i >= GEMM3M_P * 2) {
kusano 2b45e8
	  min_i = GEMM3M_P;
kusano 2b45e8
	} else 
kusano 2b45e8
	  if (min_i > GEMM3M_P) {
kusano 2b45e8
	    min_i = (min_i / 2 + GEMM3M_UNROLL_M - 1) & ~(GEMM3M_UNROLL_M - 1);
kusano 2b45e8
	  }
kusano 2b45e8
	
kusano 2b45e8
	START_RPCC();
kusano 2b45e8
	
kusano 2b45e8
	ICOPYB_OPERATION(min_l, min_i, a, lda, ls, is, sa);
kusano 2b45e8
	
kusano 2b45e8
	STOP_RPCC(innercost);
kusano 2b45e8
	
kusano 2b45e8
	START_RPCC();
kusano 2b45e8
	
kusano 2b45e8
	KERNEL_OPERATION(min_i, min_j, min_l, ALPHA5, ALPHA6, sa, sb, c, ldc, is, js);
kusano 2b45e8
	
kusano 2b45e8
	STOP_RPCC(kernelcost);
kusano 2b45e8
      }
kusano 2b45e8
kusano 2b45e8
      min_i = m_to - m_from;
kusano 2b45e8
      if (min_i >= GEMM3M_P * 2) {
kusano 2b45e8
	min_i = GEMM3M_P;
kusano 2b45e8
      } else {
kusano 2b45e8
	if (min_i > GEMM3M_P) {
kusano 2b45e8
	  min_i = (min_i / 2 + GEMM3M_UNROLL_M - 1) & ~(GEMM3M_UNROLL_M - 1);
kusano 2b45e8
	}
kusano 2b45e8
      }
kusano 2b45e8
      
kusano 2b45e8
      START_RPCC();
kusano 2b45e8
      
kusano 2b45e8
      ICOPYR_OPERATION(min_l, min_i, a, lda, ls, m_from, sa);
kusano 2b45e8
      
kusano 2b45e8
      STOP_RPCC(innercost);
kusano 2b45e8
      
kusano 2b45e8
      for(jjs = js; jjs < js + min_j; jjs += min_jj){
kusano 2b45e8
	min_jj = min_j + js - jjs;
kusano 2b45e8
	if (min_jj > GEMM3M_UNROLL_N) min_jj = GEMM3M_UNROLL_N;
kusano 2b45e8
	
kusano 2b45e8
	START_RPCC();
kusano 2b45e8
	
kusano 2b45e8
#if   defined(NN) || defined(NT) || defined(TN) || defined(TT)
kusano 2b45e8
	OCOPYR_OPERATION(min_l, min_jj, b, ldb, alpha[0],  alpha[1], ls, jjs, sb + min_l * (jjs - js));
kusano 2b45e8
#elif defined(RR) || defined(RC) || defined(CR) || defined(CC)
kusano 2b45e8
	OCOPYR_OPERATION(min_l, min_jj, b, ldb, alpha[0], -alpha[1], ls, jjs, sb + min_l * (jjs - js));
kusano 2b45e8
#elif defined(RN) || defined(RT) || defined(CN) || defined(CT)
kusano 2b45e8
	OCOPYI_OPERATION(min_l, min_jj, b, ldb, alpha[0],  alpha[1], ls, jjs, sb + min_l * (jjs - js));
kusano 2b45e8
#else
kusano 2b45e8
	OCOPYI_OPERATION(min_l, min_jj, b, ldb, alpha[0], -alpha[1], ls, jjs, sb + min_l * (jjs - js));
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
	STOP_RPCC(outercost);
kusano 2b45e8
	
kusano 2b45e8
	START_RPCC();
kusano 2b45e8
	
kusano 2b45e8
	KERNEL_OPERATION(min_i, min_jj, min_l, ALPHA11, ALPHA12,
kusano 2b45e8
			 sa, sb + min_l * (jjs - js), c, ldc, m_from, jjs);
kusano 2b45e8
	
kusano 2b45e8
	STOP_RPCC(kernelcost);
kusano 2b45e8
	
kusano 2b45e8
      }      
kusano 2b45e8
      
kusano 2b45e8
      for(is = m_from + min_i; is < m_to; is += min_i){
kusano 2b45e8
	min_i = m_to - is;
kusano 2b45e8
	if (min_i >= GEMM3M_P * 2) {
kusano 2b45e8
	  min_i = GEMM3M_P;
kusano 2b45e8
	} else 
kusano 2b45e8
	  if (min_i > GEMM3M_P) {
kusano 2b45e8
	    min_i = (min_i / 2 + GEMM3M_UNROLL_M - 1) & ~(GEMM3M_UNROLL_M - 1);
kusano 2b45e8
	  }
kusano 2b45e8
	
kusano 2b45e8
	START_RPCC();
kusano 2b45e8
	
kusano 2b45e8
	ICOPYR_OPERATION(min_l, min_i, a, lda, ls, is, sa);
kusano 2b45e8
	
kusano 2b45e8
	STOP_RPCC(innercost);
kusano 2b45e8
	
kusano 2b45e8
	START_RPCC();
kusano 2b45e8
	
kusano 2b45e8
	KERNEL_OPERATION(min_i, min_j, min_l, ALPHA11, ALPHA12, sa, sb, c, ldc, is, js);
kusano 2b45e8
	
kusano 2b45e8
	STOP_RPCC(kernelcost);
kusano 2b45e8
	
kusano 2b45e8
      }
kusano 2b45e8
kusano 2b45e8
      min_i = m_to - m_from;
kusano 2b45e8
      if (min_i >= GEMM3M_P * 2) {
kusano 2b45e8
	min_i = GEMM3M_P;
kusano 2b45e8
      } else {
kusano 2b45e8
	if (min_i > GEMM3M_P) {
kusano 2b45e8
	  min_i = (min_i / 2 + GEMM3M_UNROLL_M - 1) & ~(GEMM3M_UNROLL_M - 1);
kusano 2b45e8
	}
kusano 2b45e8
      }
kusano 2b45e8
      
kusano 2b45e8
      START_RPCC();
kusano 2b45e8
      
kusano 2b45e8
      ICOPYI_OPERATION(min_l, min_i, a, lda, ls, m_from, sa);
kusano 2b45e8
      
kusano 2b45e8
      STOP_RPCC(innercost);
kusano 2b45e8
      
kusano 2b45e8
      for(jjs = js; jjs < js + min_j; jjs += min_jj){
kusano 2b45e8
	min_jj = min_j + js - jjs;
kusano 2b45e8
	if (min_jj > GEMM3M_UNROLL_N) min_jj = GEMM3M_UNROLL_N;
kusano 2b45e8
	
kusano 2b45e8
	START_RPCC();
kusano 2b45e8
	
kusano 2b45e8
#if   defined(NN) || defined(NT) || defined(TN) || defined(TT) 
kusano 2b45e8
	OCOPYI_OPERATION(min_l, min_jj, b, ldb, alpha[0],  alpha[1], ls, jjs, sb + min_l * (jjs - js));
kusano 2b45e8
#elif defined(RR) || defined(RC) || defined(CR) || defined(CC)
kusano 2b45e8
	OCOPYI_OPERATION(min_l, min_jj, b, ldb, alpha[0], -alpha[1], ls, jjs, sb + min_l * (jjs - js));
kusano 2b45e8
#elif defined(RN) || defined(RT) || defined(CN) || defined(CT)
kusano 2b45e8
	OCOPYR_OPERATION(min_l, min_jj, b, ldb, alpha[0],  alpha[1], ls, jjs, sb + min_l * (jjs - js));
kusano 2b45e8
#else
kusano 2b45e8
	OCOPYR_OPERATION(min_l, min_jj, b, ldb, alpha[0], -alpha[1], ls, jjs, sb + min_l * (jjs - js));
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
	STOP_RPCC(outercost);
kusano 2b45e8
	
kusano 2b45e8
	START_RPCC();
kusano 2b45e8
	
kusano 2b45e8
	KERNEL_OPERATION(min_i, min_jj, min_l, ALPHA17, ALPHA18,
kusano 2b45e8
			 sa, sb + min_l * (jjs - js), c, ldc, m_from, jjs);
kusano 2b45e8
	
kusano 2b45e8
	STOP_RPCC(kernelcost);
kusano 2b45e8
	
kusano 2b45e8
      }      
kusano 2b45e8
      
kusano 2b45e8
      for(is = m_from + min_i; is < m_to; is += min_i){
kusano 2b45e8
	min_i = m_to - is;
kusano 2b45e8
	if (min_i >= GEMM3M_P * 2) {
kusano 2b45e8
	  min_i = GEMM3M_P;
kusano 2b45e8
	} else 
kusano 2b45e8
	  if (min_i > GEMM3M_P) {
kusano 2b45e8
	    min_i = (min_i / 2 + GEMM3M_UNROLL_M - 1) & ~(GEMM3M_UNROLL_M - 1);
kusano 2b45e8
	  }
kusano 2b45e8
	
kusano 2b45e8
	START_RPCC();
kusano 2b45e8
	
kusano 2b45e8
	ICOPYI_OPERATION(min_l, min_i, a, lda, ls, is, sa);
kusano 2b45e8
	
kusano 2b45e8
	STOP_RPCC(innercost);
kusano 2b45e8
	
kusano 2b45e8
	START_RPCC();
kusano 2b45e8
	
kusano 2b45e8
	KERNEL_OPERATION(min_i, min_j, min_l, ALPHA17, ALPHA18, sa, sb, c, ldc, is, js);
kusano 2b45e8
	
kusano 2b45e8
	STOP_RPCC(kernelcost);
kusano 2b45e8
	
kusano 2b45e8
      }
kusano 2b45e8
kusano 2b45e8
    } /* end of js */
kusano 2b45e8
  } /* end of ls */
kusano 2b45e8
  
kusano 2b45e8
kusano 2b45e8
#ifdef TIMING
kusano 2b45e8
  total = (double)outercost + (double)innercost + (double)kernelcost;
kusano 2b45e8
kusano 2b45e8
  printf( "Copy A : %5.2f Copy  B: %5.2f  Kernel : %5.2f\n",
kusano 2b45e8
	   innercost / total * 100., outercost / total * 100.,
kusano 2b45e8
	  kernelcost / total * 100.);
kusano 2b45e8
kusano 2b45e8
  printf( " Total %10.3f%%  %10.3f MFlops\n",
kusano 2b45e8
	  ((double)(m_to - m_from) * (double)(n_to - n_from) * (double)k) / (double)kernelcost / 2 * 100,
kusano 2b45e8
	  2400. * (2. * (double)(m_to - m_from) * (double)(n_to - n_from) * (double)k) / (double)kernelcost);
kusano 2b45e8
#endif
kusano 2b45e8
  
kusano 2b45e8
  return 0;
kusano 2b45e8
}