Blame thirdparty/openblas/xianyi-OpenBLAS-e6e87a2/lapack/trtri/trtri_L_single.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
static FLOAT dp1 =  1.;
kusano 2b45e8
static FLOAT dm1 = -1.;
kusano 2b45e8
kusano 2b45e8
#ifdef UNIT
kusano 2b45e8
#define TRTI2	TRTI2_LU
kusano 2b45e8
#else
kusano 2b45e8
#define TRTI2	TRTI2_LN
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 20
kusano 2b45e8
#define GEMM_R 64
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#define GEMM_PQ  MAX(GEMM_P, GEMM_Q)
kusano 2b45e8
#define REAL_GEMM_R (GEMM_R - 2 * GEMM_PQ)
kusano 2b45e8
kusano 2b45e8
blasint CNAME(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa, FLOAT *sb, BLASLONG myid) {
kusano 2b45e8
kusano 2b45e8
  BLASLONG  n, lda;
kusano 2b45e8
  FLOAT *a;
kusano 2b45e8
kusano 2b45e8
  BLASLONG i, is, min_i, start_i;
kusano 2b45e8
  BLASLONG ls, min_l;
kusano 2b45e8
  BLASLONG bk;
kusano 2b45e8
  BLASLONG blocking;
kusano 2b45e8
  BLASLONG range_N[2];
kusano 2b45e8
kusano 2b45e8
  FLOAT *sa_trsm = (FLOAT *)((BLASLONG)sb);
kusano 2b45e8
  FLOAT *sa_trmm = (FLOAT *)((((BLASLONG)sb
kusano 2b45e8
			       + GEMM_PQ * GEMM_Q * COMPSIZE * SIZE + GEMM_ALIGN) & ~GEMM_ALIGN)
kusano 2b45e8
			     + GEMM_OFFSET_A);
kusano 2b45e8
  FLOAT *sb_gemm = (FLOAT *)((((BLASLONG)sa_trmm
kusano 2b45e8
			       + GEMM_PQ * GEMM_Q * COMPSIZE * SIZE + GEMM_ALIGN) & ~GEMM_ALIGN)
kusano 2b45e8
			     + GEMM_OFFSET_B);
kusano 2b45e8
kusano 2b45e8
  n      = args -> n;
kusano 2b45e8
  a      = (FLOAT *)args -> a;
kusano 2b45e8
  lda    = args -> lda;
kusano 2b45e8
kusano 2b45e8
  if (range_n) {
kusano 2b45e8
    n      = range_n[1] - range_n[0];
kusano 2b45e8
    a     += range_n[0] * (lda + 1) * COMPSIZE;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (n <= DTB_ENTRIES) {
kusano 2b45e8
    TRTI2(args, NULL, range_n, sa, sb, 0);
kusano 2b45e8
    return 0;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  blocking = GEMM_Q;
kusano 2b45e8
  if (n <= 4 * GEMM_Q) blocking = (n + 3) / 4;
kusano 2b45e8
kusano 2b45e8
  start_i = 0;
kusano 2b45e8
  while (start_i < n) start_i += blocking;
kusano 2b45e8
  start_i -= blocking;
kusano 2b45e8
kusano 2b45e8
  for (i = start_i; i >= 0; i -= blocking) {
kusano 2b45e8
    bk = MIN(blocking, n - i);
kusano 2b45e8
    
kusano 2b45e8
    if (n - bk - i > 0) TRSM_OLNCOPY(bk, bk, a + (i + i * lda) * COMPSIZE, lda, 0, sa_trsm);
kusano 2b45e8
	
kusano 2b45e8
    if (!range_n) {
kusano 2b45e8
      range_N[0] = i;
kusano 2b45e8
      range_N[1] = i + bk;
kusano 2b45e8
    } else {
kusano 2b45e8
      range_N[0] = range_n[0] + i;
kusano 2b45e8
      range_N[1] = range_n[0] + i + bk;
kusano 2b45e8
    }
kusano 2b45e8
kusano 2b45e8
    CNAME(args, NULL, range_N, sa, sa_trmm, 0);
kusano 2b45e8
kusano 2b45e8
    if (i > 0) {
kusano 2b45e8
      TRMM_ILTCOPY(bk, bk, a + (i + i * lda) * COMPSIZE, lda, 0, 0, sa_trmm);
kusano 2b45e8
kusano 2b45e8
      for (ls = 0; ls < i; ls += REAL_GEMM_R) {
kusano 2b45e8
	min_l = i - ls;
kusano 2b45e8
	if (min_l > REAL_GEMM_R) min_l = REAL_GEMM_R;
kusano 2b45e8
	
kusano 2b45e8
	GEMM_ONCOPY (bk, min_l, a + (i + ls * lda) * COMPSIZE, lda, sb_gemm);
kusano 2b45e8
	
kusano 2b45e8
	if (n - bk - i > 0) {
kusano 2b45e8
	  for (is = i + bk; is < n; is += GEMM_P) {
kusano 2b45e8
	    min_i = n - is;
kusano 2b45e8
	    if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	    
kusano 2b45e8
	    if (ls == 0) {
kusano 2b45e8
	      NEG_TCOPY (bk, min_i, a + (is + i * lda) * COMPSIZE, lda, sa);
kusano 2b45e8
kusano 2b45e8
	      TRSM_KERNEL_RT(min_i, bk, bk, dm1, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
			     ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
			     sa, sa_trsm,
kusano 2b45e8
			     a + (is + i * lda) * COMPSIZE, lda, 0);
kusano 2b45e8
	    } else {
kusano 2b45e8
	      GEMM_ITCOPY (bk, min_i, a + (is + i * lda) * COMPSIZE, lda, sa);
kusano 2b45e8
	    }
kusano 2b45e8
kusano 2b45e8
	    GEMM_KERNEL_N(min_i, min_l, bk, dp1, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
			  ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
			  sa, sb_gemm,
kusano 2b45e8
			  a + (is + ls * lda) * COMPSIZE, lda);
kusano 2b45e8
	  }
kusano 2b45e8
	}
kusano 2b45e8
	
kusano 2b45e8
	for (is = 0; is < bk; is += GEMM_P) {
kusano 2b45e8
	  min_i = bk - is;
kusano 2b45e8
	  if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	  
kusano 2b45e8
	  TRMM_KERNEL_LT(min_i, min_l, bk, dp1, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
			 ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
			 sa_trmm + is * bk * COMPSIZE, sb_gemm,
kusano 2b45e8
			 a + (i + is + ls * lda) * COMPSIZE, lda, is);
kusano 2b45e8
	}
kusano 2b45e8
      }
kusano 2b45e8
kusano 2b45e8
    } else {
kusano 2b45e8
kusano 2b45e8
      if (n - bk - i > 0) {
kusano 2b45e8
	for (is = 0; is < n - bk - i; is += GEMM_P) {
kusano 2b45e8
	  min_i = n - bk - i - is;
kusano 2b45e8
	  if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	  
kusano 2b45e8
	  NEG_TCOPY (bk, min_i, a + (i + bk + is + i * lda) * COMPSIZE, lda, sa);
kusano 2b45e8
	  
kusano 2b45e8
	  TRSM_KERNEL_RT(min_i, bk, bk, dm1, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
			 ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
			 sa, sa_trsm,
kusano 2b45e8
			 a + (i + bk + is + i * lda) * COMPSIZE, lda, 0);
kusano 2b45e8
	}
kusano 2b45e8
      }
kusano 2b45e8
      
kusano 2b45e8
    }
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  return 0;
kusano 2b45e8
}