Blame thirdparty/openblas/xianyi-OpenBLAS-e6e87a2/driver/level3/trsm_L.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 dm1 = -1.;
kusano 2b45e8
kusano 2b45e8
#ifdef CONJ
kusano 2b45e8
#define GEMM_KERNEL   GEMM_KERNEL_L
kusano 2b45e8
#if (!defined(TRANSA) && defined(UPPER)) || (defined(TRANSA) && !defined(UPPER))
kusano 2b45e8
#define TRSM_KERNEL   TRSM_KERNEL_LR
kusano 2b45e8
#else
kusano 2b45e8
#define TRSM_KERNEL   TRSM_KERNEL_LC
kusano 2b45e8
#endif
kusano 2b45e8
#else
kusano 2b45e8
#define GEMM_KERNEL   GEMM_KERNEL_N
kusano 2b45e8
#if (!defined(TRANSA) && defined(UPPER)) || (defined(TRANSA) && !defined(UPPER))
kusano 2b45e8
#define TRSM_KERNEL   TRSM_KERNEL_LN
kusano 2b45e8
#else
kusano 2b45e8
#define TRSM_KERNEL   TRSM_KERNEL_LT
kusano 2b45e8
#endif
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 1600
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_n) {
kusano 2b45e8
    BLASLONG n_from = *(((BLASLONG *)range_n) + 0);
kusano 2b45e8
    BLASLONG n_to   = *(((BLASLONG *)range_n) + 1);
kusano 2b45e8
kusano 2b45e8
    n = n_to - n_from;
kusano 2b45e8
kusano 2b45e8
    b += n_from * ldb * 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
  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
#if (!defined(UPPER) && !defined(TRANSA)) || (defined(UPPER) && defined(TRANSA))
kusano 2b45e8
    for(ls = 0; ls < m; ls += GEMM_Q){
kusano 2b45e8
      min_l = m - ls;
kusano 2b45e8
      if (min_l > GEMM_Q) min_l = GEMM_Q;
kusano 2b45e8
      min_i = min_l;
kusano 2b45e8
      if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
      
kusano 2b45e8
#ifndef TRANSA
kusano 2b45e8
      TRSM_ILTCOPY(min_l, min_i, a + (ls + ls * lda) * COMPSIZE, lda, 0, sa);
kusano 2b45e8
#else
kusano 2b45e8
      TRSM_IUNCOPY(min_l, min_i, a + (ls + ls * lda) * COMPSIZE, lda, 0, sa);
kusano 2b45e8
#endif
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
	GEMM_ONCOPY(min_l, min_jj, b + (ls + jjs * ldb) * COMPSIZE, ldb, sb + min_l * (jjs - js) * COMPSIZE);
kusano 2b45e8
kusano 2b45e8
	TRSM_KERNEL(min_i, min_jj, min_l, dm1,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		    ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		    sa, sb + min_l * (jjs - js) * COMPSIZE, 
kusano 2b45e8
		    b + (ls + jjs * ldb) * COMPSIZE, ldb, 0);
kusano 2b45e8
      }
kusano 2b45e8
kusano 2b45e8
      for(is = ls + min_i; is < ls + min_l; is += GEMM_P){
kusano 2b45e8
	min_i = ls + min_l - is;
kusano 2b45e8
	if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	
kusano 2b45e8
#ifndef TRANSA
kusano 2b45e8
	TRSM_ILTCOPY(min_l, min_i, a + (is + ls * lda) * COMPSIZE, lda, is - ls, sa);
kusano 2b45e8
#else
kusano 2b45e8
	TRSM_IUNCOPY(min_l, min_i, a + (ls + is * lda) * COMPSIZE, lda, is - ls, sa);
kusano 2b45e8
#endif
kusano 2b45e8
	
kusano 2b45e8
	TRSM_KERNEL(min_i, min_j, min_l, dm1,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		    ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		    sa, sb, b + (is + js * ldb) * COMPSIZE, ldb, is - ls);
kusano 2b45e8
      }
kusano 2b45e8
      
kusano 2b45e8
kusano 2b45e8
      for(is = ls + min_l; 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
#ifndef TRANSA
kusano 2b45e8
	GEMM_ITCOPY(min_l, min_i, a + (is + ls * lda) * COMPSIZE, lda, sa);
kusano 2b45e8
#else
kusano 2b45e8
	GEMM_INCOPY(min_l, min_i, a + (ls + is * lda) * COMPSIZE, lda, sa);
kusano 2b45e8
#endif
kusano 2b45e8
	
kusano 2b45e8
	GEMM_KERNEL(min_i, min_j, min_l, dm1, 
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
#else
kusano 2b45e8
    BLASLONG start_is;
kusano 2b45e8
kusano 2b45e8
    for(ls = m; ls > 0; ls -= GEMM_Q){
kusano 2b45e8
      min_l = ls;
kusano 2b45e8
      if (min_l > GEMM_Q) min_l = GEMM_Q;
kusano 2b45e8
      start_is = ls - min_l;
kusano 2b45e8
      while (start_is + GEMM_P < ls) start_is += GEMM_P;
kusano 2b45e8
      min_i = ls - start_is;
kusano 2b45e8
      if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
kusano 2b45e8
#ifndef TRANSA
kusano 2b45e8
      TRSM_IUTCOPY(min_l, min_i, a + (start_is + (ls - min_l) * lda) * COMPSIZE, lda, start_is - (ls - min_l), sa);
kusano 2b45e8
#else
kusano 2b45e8
      TRSM_ILNCOPY(min_l, min_i, a + ((ls - min_l) + start_is * lda) * COMPSIZE, lda, start_is - (ls - min_l), sa);
kusano 2b45e8
#endif
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
	GEMM_ONCOPY(min_l, min_jj, b + (ls - min_l + jjs * ldb) * COMPSIZE, ldb, sb + min_l * (jjs - js) * COMPSIZE);
kusano 2b45e8
	
kusano 2b45e8
	TRSM_KERNEL(min_i, min_jj, min_l, dm1,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		    ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		    sa, sb + min_l * (jjs - js) * COMPSIZE, 
kusano 2b45e8
		    b +  (start_is + jjs * ldb) * COMPSIZE, ldb,  start_is - ls + min_l);
kusano 2b45e8
      }
kusano 2b45e8
      
kusano 2b45e8
      for(is = start_is - GEMM_P; is >= ls - min_l; is -= GEMM_P){
kusano 2b45e8
	min_i = ls - is;
kusano 2b45e8
	if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	
kusano 2b45e8
#ifndef TRANSA
kusano 2b45e8
	TRSM_IUTCOPY(min_l, min_i, a + (is + (ls - min_l) * lda) * COMPSIZE, lda, is - (ls - min_l), sa);
kusano 2b45e8
#else
kusano 2b45e8
	TRSM_ILNCOPY(min_l, min_i, a + ((ls - min_l) + is * lda) * COMPSIZE, lda, is - (ls - min_l), sa);
kusano 2b45e8
#endif
kusano 2b45e8
	TRSM_KERNEL(min_i, min_j, min_l, dm1,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		    ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		    sa, sb, 
kusano 2b45e8
		    b +  (is + js * ldb) * COMPSIZE, ldb,  + is - (ls - min_l) );
kusano 2b45e8
      }
kusano 2b45e8
kusano 2b45e8
      
kusano 2b45e8
      for(is = 0; is < ls - min_l; is += GEMM_P){
kusano 2b45e8
	min_i = ls - min_l - is;
kusano 2b45e8
	if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	
kusano 2b45e8
#ifndef TRANSA
kusano 2b45e8
	GEMM_ITCOPY(min_l, min_i, a + (is + (ls - min_l) * lda) * COMPSIZE, lda, sa);
kusano 2b45e8
#else
kusano 2b45e8
	GEMM_INCOPY(min_l, min_i, a + ((ls - min_l) + is * lda) * COMPSIZE, lda, sa);
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
	GEMM_KERNEL(min_i, min_j, min_l, dm1, 
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
#endif
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  return 0;
kusano 2b45e8
}