Blame thirdparty/openblas/xianyi-OpenBLAS-e6e87a2/driver/level3/trmm_R.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 <ctype.h></ctype.h>
kusano 2b45e8
#include "common.h"
kusano 2b45e8
kusano 2b45e8
const static FLOAT dp1 = 1.;
kusano 2b45e8
kusano 2b45e8
#ifdef CONJ
kusano 2b45e8
#define GEMM_KERNEL   GEMM_KERNEL_R
kusano 2b45e8
#define TRMM_KERNEL_N TRMM_KERNEL_RR
kusano 2b45e8
#define TRMM_KERNEL_T TRMM_KERNEL_RC
kusano 2b45e8
#else
kusano 2b45e8
#define GEMM_KERNEL   GEMM_KERNEL_N
kusano 2b45e8
#define TRMM_KERNEL_N TRMM_KERNEL_RN
kusano 2b45e8
#define TRMM_KERNEL_T TRMM_KERNEL_RT
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#if 0
kusano 2b45e8
#undef GEMM_P
kusano 2b45e8
#undef GEMM_Q
kusano 2b45e8
#undef GEMM_R
kusano 2b45e8
kusano 2b45e8
#define GEMM_P 8
kusano 2b45e8
#define GEMM_Q 12
kusano 2b45e8
#define GEMM_R 16
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
int CNAME(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa, FLOAT *sb, BLASLONG dummy) {
kusano 2b45e8
kusano 2b45e8
  BLASLONG m, n, lda, ldb;
kusano 2b45e8
  FLOAT *beta, *a, *b;
kusano 2b45e8
kusano 2b45e8
  BLASLONG ls, is, js;
kusano 2b45e8
  BLASLONG min_l, min_i, min_j;
kusano 2b45e8
  BLASLONG jjs, min_jj;
kusano 2b45e8
kusano 2b45e8
  m = args -> m;
kusano 2b45e8
  n = args -> n;
kusano 2b45e8
kusano 2b45e8
  a = (FLOAT *)args -> a;
kusano 2b45e8
  b = (FLOAT *)args -> b;
kusano 2b45e8
kusano 2b45e8
  lda = args -> lda;
kusano 2b45e8
  ldb = args -> ldb;
kusano 2b45e8
kusano 2b45e8
  beta  = (FLOAT *)args -> beta;
kusano 2b45e8
kusano 2b45e8
  if (range_m) {
kusano 2b45e8
    BLASLONG m_from = *(((BLASLONG *)range_m) + 0);
kusano 2b45e8
    BLASLONG m_to   = *(((BLASLONG *)range_m) + 1);
kusano 2b45e8
kusano 2b45e8
    m = m_to - m_from;
kusano 2b45e8
kusano 2b45e8
    b += m_from * COMPSIZE;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (beta) {
kusano 2b45e8
#ifndef COMPLEX
kusano 2b45e8
    if (beta[0] != ONE)
kusano 2b45e8
      GEMM_BETA(m, n, 0, beta[0], NULL, 0, NULL, 0, b, ldb);
kusano 2b45e8
    if (beta[0] == ZERO) return 0;
kusano 2b45e8
#else
kusano 2b45e8
    if ((beta[0] != ONE) || (beta[1] != ZERO))
kusano 2b45e8
      GEMM_BETA(m, n, 0, beta[0], beta[1], NULL, 0, NULL, 0, b, ldb);
kusano 2b45e8
    if ((beta[0] == ZERO) && (beta[1] == ZERO)) return 0;
kusano 2b45e8
#endif
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
#if (!defined(UPPER) && !defined(TRANSA)) || (defined(UPPER) && defined(TRANSA))
kusano 2b45e8
kusano 2b45e8
  for(js = 0; js < n; js += GEMM_R){
kusano 2b45e8
    min_j = n - js;
kusano 2b45e8
    if (min_j > GEMM_R) min_j = GEMM_R;
kusano 2b45e8
kusano 2b45e8
    for(ls = js; ls < js + min_j; ls += GEMM_Q){
kusano 2b45e8
      min_l = js + min_j - ls;
kusano 2b45e8
      if (min_l > GEMM_Q) min_l = GEMM_Q;
kusano 2b45e8
      min_i = m;
kusano 2b45e8
      if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
      
kusano 2b45e8
      GEMM_ITCOPY(min_l, min_i, b + (ls * ldb) * COMPSIZE, ldb, sa);
kusano 2b45e8
      
kusano 2b45e8
      for(jjs = 0; jjs < ls - js; jjs += min_jj){
kusano 2b45e8
	min_jj = ls - js - jjs;
kusano 2b45e8
	if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
kusano 2b45e8
kusano 2b45e8
#ifndef TRANSA
kusano 2b45e8
	GEMM_ONCOPY(min_l, min_jj, a + (ls + (js + jjs) * lda) * COMPSIZE, lda, sb + min_l * jjs * COMPSIZE);
kusano 2b45e8
#else
kusano 2b45e8
	GEMM_OTCOPY(min_l, min_jj, a + ((js + jjs) + ls * lda) * COMPSIZE, lda, sb + min_l * jjs * COMPSIZE);
kusano 2b45e8
#endif
kusano 2b45e8
		
kusano 2b45e8
	GEMM_KERNEL(min_i, min_jj, min_l, dp1, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		    ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		    sa, sb + min_l * jjs * COMPSIZE,
kusano 2b45e8
		    b + ((js + jjs) * ldb) * COMPSIZE, ldb); 
kusano 2b45e8
      }
kusano 2b45e8
kusano 2b45e8
      for(jjs = 0; jjs < min_l; jjs += min_jj){
kusano 2b45e8
	min_jj = min_l - jjs;
kusano 2b45e8
	if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
kusano 2b45e8
	
kusano 2b45e8
#ifndef TRANSA
kusano 2b45e8
	TRMM_OLNCOPY(min_l, min_jj, a, lda, ls, ls + jjs, sb + min_l * (ls - js + jjs) * COMPSIZE);
kusano 2b45e8
#else
kusano 2b45e8
	TRMM_OUTCOPY(min_l, min_jj, a, lda, ls, ls + jjs, sb + min_l * (ls - js + jjs) * COMPSIZE);
kusano 2b45e8
#endif
kusano 2b45e8
	
kusano 2b45e8
	TRMM_KERNEL_T(min_i, min_jj, min_l, dp1,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		      ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		      sa,
kusano 2b45e8
		      sb + (ls - js + jjs) * min_l * COMPSIZE,
kusano 2b45e8
		      b + ((ls + jjs) * ldb) * COMPSIZE, ldb, -jjs); 
kusano 2b45e8
      }
kusano 2b45e8
kusano 2b45e8
      for(is = min_i; is < m; is += GEMM_P){
kusano 2b45e8
	min_i = m - is;
kusano 2b45e8
	if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	
kusano 2b45e8
	GEMM_ITCOPY(min_l, min_i, b + (is + ls * ldb) * COMPSIZE, ldb, sa);
kusano 2b45e8
	
kusano 2b45e8
	GEMM_KERNEL(min_i, ls - js, min_l, dp1, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		    ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		    sa, sb,
kusano 2b45e8
		    b + (is + js * ldb) * COMPSIZE, ldb); 
kusano 2b45e8
	
kusano 2b45e8
	TRMM_KERNEL_T(min_i, min_l, min_l, dp1,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		      ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		      sa,
kusano 2b45e8
		      sb + (ls - js) * min_l * COMPSIZE,
kusano 2b45e8
		      b + (is + ls * ldb) * COMPSIZE, ldb, 0); 
kusano 2b45e8
      }
kusano 2b45e8
    }
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
    for(ls = js + min_j; ls < n; ls += GEMM_Q){
kusano 2b45e8
      min_l = n - ls;
kusano 2b45e8
      if (min_l > GEMM_Q) min_l = GEMM_Q;
kusano 2b45e8
      min_i = m;
kusano 2b45e8
      if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	
kusano 2b45e8
      GEMM_ITCOPY(min_l, min_i, b + (ls * ldb) * COMPSIZE, ldb, sa);
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 > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
kusano 2b45e8
kusano 2b45e8
#ifndef TRANSA
kusano 2b45e8
	GEMM_ONCOPY(min_l, min_jj, a + (ls + jjs * lda) * COMPSIZE, lda, sb + min_l * (jjs - js) * COMPSIZE);
kusano 2b45e8
#else
kusano 2b45e8
	GEMM_OTCOPY(min_l, min_jj, a + (jjs + ls * lda) * COMPSIZE, lda, sb + min_l * (jjs - js) * COMPSIZE);
kusano 2b45e8
#endif
kusano 2b45e8
	
kusano 2b45e8
	GEMM_KERNEL(min_i, min_jj, min_l, dp1, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		    ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		    sa, sb + min_l * (jjs - js) * COMPSIZE, 
kusano 2b45e8
		    b + (jjs * ldb) * COMPSIZE, ldb); 
kusano 2b45e8
      }
kusano 2b45e8
      
kusano 2b45e8
      for(is = min_i; is < m; is += GEMM_P){
kusano 2b45e8
	min_i = m - is;
kusano 2b45e8
	if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	
kusano 2b45e8
	GEMM_ITCOPY(min_l, min_i, b + (is + ls * ldb) * COMPSIZE, ldb, sa);
kusano 2b45e8
	
kusano 2b45e8
	GEMM_KERNEL(min_i, min_j, min_l, dp1, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		    ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		    sa, sb, b + (is + js * ldb) * COMPSIZE, ldb); 
kusano 2b45e8
      }
kusano 2b45e8
    }
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
#else
kusano 2b45e8
  BLASLONG start_ls;
kusano 2b45e8
kusano 2b45e8
  for(js = n; js > 0; js -= GEMM_R){
kusano 2b45e8
    min_j = js;
kusano 2b45e8
    if (min_j > GEMM_R) min_j = GEMM_R;
kusano 2b45e8
    
kusano 2b45e8
    start_ls = js - min_j;
kusano 2b45e8
    while (start_ls + GEMM_Q < js) start_ls += GEMM_Q;
kusano 2b45e8
kusano 2b45e8
    for(ls = start_ls; ls >= js - min_j; ls -= GEMM_Q){
kusano 2b45e8
      min_l = js - ls;
kusano 2b45e8
      if (min_l > GEMM_Q) min_l = GEMM_Q;
kusano 2b45e8
      min_i = m;
kusano 2b45e8
      if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	
kusano 2b45e8
      GEMM_ITCOPY(min_l, min_i, b + (ls * ldb) * COMPSIZE, ldb, sa);
kusano 2b45e8
kusano 2b45e8
      for(jjs = 0; jjs < min_l; jjs += min_jj){
kusano 2b45e8
	min_jj = min_l - jjs;
kusano 2b45e8
	if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
kusano 2b45e8
kusano 2b45e8
#ifndef TRANSA
kusano 2b45e8
	TRMM_OUNCOPY(min_l, min_jj, a, lda, ls, ls + jjs, sb + min_l * jjs * COMPSIZE);
kusano 2b45e8
#else
kusano 2b45e8
	TRMM_OLTCOPY(min_l, min_jj, a, lda, ls, ls + jjs, sb + min_l * jjs * COMPSIZE);
kusano 2b45e8
#endif
kusano 2b45e8
	
kusano 2b45e8
	TRMM_KERNEL_N(min_i, min_jj, min_l, dp1,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		      ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		      sa,
kusano 2b45e8
		      sb + min_l * jjs * COMPSIZE,
kusano 2b45e8
		      b + ((ls + jjs) * ldb) * COMPSIZE, ldb, -jjs); 
kusano 2b45e8
      }
kusano 2b45e8
      
kusano 2b45e8
      for(jjs = 0; jjs < js - ls - min_l; jjs += min_jj){
kusano 2b45e8
	min_jj = js - ls - min_l - jjs;
kusano 2b45e8
	if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
kusano 2b45e8
	
kusano 2b45e8
#ifndef TRANSA
kusano 2b45e8
	GEMM_ONCOPY(min_l, min_jj, a + (ls + (ls + min_l + jjs) * lda) * COMPSIZE, lda,
kusano 2b45e8
		    sb + min_l * (min_l + jjs) * COMPSIZE);
kusano 2b45e8
#else
kusano 2b45e8
	GEMM_OTCOPY(min_l, min_jj, a + ((ls + min_l + jjs) + ls * lda) * COMPSIZE, lda,
kusano 2b45e8
		    sb + min_l * (min_l + jjs) * COMPSIZE);
kusano 2b45e8
#endif
kusano 2b45e8
	
kusano 2b45e8
	GEMM_KERNEL(min_i, min_jj, min_l, dp1, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		    ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		    sa,
kusano 2b45e8
		    sb + min_l * (min_l + jjs) * COMPSIZE,
kusano 2b45e8
		    b + ((ls + min_l + jjs) * ldb) * COMPSIZE, ldb); 
kusano 2b45e8
      }
kusano 2b45e8
      
kusano 2b45e8
      for(is = min_i; is < m; is += GEMM_P){
kusano 2b45e8
	min_i = m - is;
kusano 2b45e8
	if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	
kusano 2b45e8
	GEMM_ITCOPY(min_l, min_i, b + (is + ls * ldb) * COMPSIZE, ldb, sa);
kusano 2b45e8
kusano 2b45e8
	TRMM_KERNEL_N(min_i, min_l, min_l, dp1,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		      ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		      sa,
kusano 2b45e8
		      sb,
kusano 2b45e8
		      b + (is + ls * ldb) * COMPSIZE, ldb, 0); 
kusano 2b45e8
kusano 2b45e8
	if (js - ls - min_l > 0) {
kusano 2b45e8
	  GEMM_KERNEL(min_i, js - ls - min_l, min_l, dp1, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		      ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		      sa,
kusano 2b45e8
		      sb + min_l * min_l * COMPSIZE,
kusano 2b45e8
		      b + (is + (ls + min_l) * ldb) * COMPSIZE, ldb); 
kusano 2b45e8
	}
kusano 2b45e8
      }
kusano 2b45e8
    }
kusano 2b45e8
kusano 2b45e8
    for(ls = 0; ls < js - min_j; ls += GEMM_Q){
kusano 2b45e8
      min_l = js - min_j - ls;
kusano 2b45e8
      if (min_l > GEMM_Q) min_l = GEMM_Q;
kusano 2b45e8
      min_i = m;
kusano 2b45e8
      if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
      
kusano 2b45e8
      GEMM_ITCOPY(min_l, min_i, b + (ls * ldb) * COMPSIZE, ldb, sa);
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 > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
kusano 2b45e8
	
kusano 2b45e8
#ifndef TRANSA
kusano 2b45e8
	GEMM_ONCOPY(min_l, min_jj, a + (ls + (jjs - min_j) * lda) * COMPSIZE, lda, sb + min_l * (jjs - js) * COMPSIZE);
kusano 2b45e8
#else
kusano 2b45e8
	GEMM_OTCOPY(min_l, min_jj, a + ((jjs - min_j) + ls * lda) * COMPSIZE, lda, sb + min_l * (jjs - js) * COMPSIZE);
kusano 2b45e8
#endif
kusano 2b45e8
	
kusano 2b45e8
	GEMM_KERNEL(min_i, min_jj, min_l, dp1, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		    ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		    sa, sb + min_l * (jjs - js) * COMPSIZE, 
kusano 2b45e8
		    b + ((jjs - min_j) * ldb) * COMPSIZE, ldb); 
kusano 2b45e8
      }
kusano 2b45e8
      
kusano 2b45e8
      for(is = min_i; is < m; is += GEMM_P){
kusano 2b45e8
	min_i = m - is;
kusano 2b45e8
	if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	
kusano 2b45e8
	GEMM_ITCOPY(min_l, min_i, b + (is + ls * ldb) * COMPSIZE, ldb, sa);
kusano 2b45e8
	
kusano 2b45e8
	GEMM_KERNEL(min_i, min_j, min_l, dp1, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		    ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		    sa, sb, b + (is + (js - min_j) * ldb) * COMPSIZE, ldb); 
kusano 2b45e8
      }
kusano 2b45e8
    }
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
  return 0;
kusano 2b45e8
}