Blame thirdparty/openblas/xianyi-OpenBLAS-e6e87a2/driver/level3/zher2k_kernel.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 CONJ
kusano 2b45e8
#define GEMM_KERNEL	GEMM_KERNEL_R
kusano 2b45e8
#define GEMM_KERNEL_B0	GEMM_KERNEL_R_B0
kusano 2b45e8
#else
kusano 2b45e8
#define GEMM_KERNEL	GEMM_KERNEL_L
kusano 2b45e8
#define GEMM_KERNEL_B0	GEMM_KERNEL_L_B0
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
int CNAME(BLASLONG m, BLASLONG n, BLASLONG k, FLOAT alpha_r, FLOAT alpha_i,
kusano 2b45e8
	   FLOAT *a, FLOAT *b, FLOAT *c, BLASLONG ldc, BLASLONG offset, int flag){
kusano 2b45e8
kusano 2b45e8
  BLASLONG i, j;
kusano 2b45e8
  BLASLONG loop;
kusano 2b45e8
  FLOAT subbuffer[GEMM_UNROLL_MN * GEMM_UNROLL_MN * COMPSIZE];
kusano 2b45e8
kusano 2b45e8
  if (m + offset < 0) {
kusano 2b45e8
#ifndef LOWER
kusano 2b45e8
    GEMM_KERNEL(m, n, k,
kusano 2b45e8
		alpha_r,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		alpha_i,
kusano 2b45e8
#endif
kusano 2b45e8
		a, b, c, ldc); 
kusano 2b45e8
#endif
kusano 2b45e8
    return 0;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (n < offset) {
kusano 2b45e8
#ifdef LOWER
kusano 2b45e8
    GEMM_KERNEL(m, n, k,
kusano 2b45e8
		alpha_r,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		alpha_i,
kusano 2b45e8
#endif
kusano 2b45e8
		a, b, c, ldc); 
kusano 2b45e8
#endif
kusano 2b45e8
    return 0;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
  if (offset > 0) {
kusano 2b45e8
#ifdef LOWER
kusano 2b45e8
    GEMM_KERNEL(m, offset, k,
kusano 2b45e8
		alpha_r,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		alpha_i,
kusano 2b45e8
#endif
kusano 2b45e8
		a, b, c, ldc); 
kusano 2b45e8
#endif
kusano 2b45e8
    b += offset * k   * COMPSIZE;
kusano 2b45e8
    c += offset * ldc * COMPSIZE;
kusano 2b45e8
    n -= offset;
kusano 2b45e8
    offset = 0;
kusano 2b45e8
kusano 2b45e8
    if (n <= 0) return 0;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (n > m + offset) {
kusano 2b45e8
#ifndef LOWER
kusano 2b45e8
      GEMM_KERNEL(m, n - m - offset, k,
kusano 2b45e8
		  alpha_r,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		  alpha_i,
kusano 2b45e8
#endif
kusano 2b45e8
		  a,
kusano 2b45e8
		  b + (m + offset) * k   * COMPSIZE,
kusano 2b45e8
		  c + (m + offset) * ldc * COMPSIZE, ldc); 
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
    n = m + offset;
kusano 2b45e8
    if (n <= 0) return 0;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
  if (offset < 0) {
kusano 2b45e8
#ifndef LOWER
kusano 2b45e8
    GEMM_KERNEL(-offset, n, k,
kusano 2b45e8
		alpha_r,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		alpha_i,
kusano 2b45e8
#endif
kusano 2b45e8
		a, b, c, ldc); 
kusano 2b45e8
#endif
kusano 2b45e8
    a -= offset * k   * COMPSIZE;
kusano 2b45e8
    c -= offset       * COMPSIZE;
kusano 2b45e8
    m += offset;
kusano 2b45e8
    offset = 0;
kusano 2b45e8
kusano 2b45e8
  if (m <= 0) return 0;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (m > n - offset) {
kusano 2b45e8
#ifdef LOWER
kusano 2b45e8
    GEMM_KERNEL(m - n + offset, n, k,
kusano 2b45e8
		alpha_r,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		alpha_i,
kusano 2b45e8
#endif
kusano 2b45e8
		a + (n - offset) * k * COMPSIZE,
kusano 2b45e8
		b,
kusano 2b45e8
		c + (n - offset)     * COMPSIZE, ldc); 
kusano 2b45e8
#endif
kusano 2b45e8
    m = n + offset;
kusano 2b45e8
  if (m <= 0) return 0;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  for (loop = 0; loop < n; loop += GEMM_UNROLL_MN) {
kusano 2b45e8
      
kusano 2b45e8
    int mm, nn;
kusano 2b45e8
    
kusano 2b45e8
    mm = (loop & ~(GEMM_UNROLL_MN - 1));
kusano 2b45e8
    nn = MIN(GEMM_UNROLL_MN, n - loop);
kusano 2b45e8
    
kusano 2b45e8
#ifndef LOWER
kusano 2b45e8
    GEMM_KERNEL(mm, nn, k,
kusano 2b45e8
		  alpha_r,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		  alpha_i,
kusano 2b45e8
#endif
kusano 2b45e8
		  a, b + loop * k * COMPSIZE, c + loop * ldc * COMPSIZE, ldc); 
kusano 2b45e8
#endif
kusano 2b45e8
    
kusano 2b45e8
    if (flag) {
kusano 2b45e8
      GEMM_BETA(nn, nn, 0, ZERO, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		NULL, 0, NULL, 0, subbuffer, nn);
kusano 2b45e8
kusano 2b45e8
      GEMM_KERNEL(nn, nn, k,
kusano 2b45e8
		    alpha_r,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		    alpha_i,
kusano 2b45e8
#endif
kusano 2b45e8
		    a + loop * k * COMPSIZE, b + loop * k * COMPSIZE, subbuffer, nn); 
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
#ifndef LOWER
kusano 2b45e8
      
kusano 2b45e8
      for (j = 0; j < nn; j ++) {
kusano 2b45e8
	for (i = 0; i <= j; i ++) {
kusano 2b45e8
	  c[(i + loop + (j + loop) * ldc) * 2 + 0] += 
kusano 2b45e8
	    subbuffer[(i + j * nn) * 2 + 0] + subbuffer[(j + i * nn) * 2 + 0];
kusano 2b45e8
	  if (i != j) {
kusano 2b45e8
	    c[(i + loop + (j + loop) * ldc) * 2 + 1] += 
kusano 2b45e8
	      subbuffer[(i + j * nn) * 2 + 1] - subbuffer[(j + i * nn) * 2 + 1];
kusano 2b45e8
	  } else {
kusano 2b45e8
	    c[(i + loop + (j + loop) * ldc) * 2 + 1] = ZERO;
kusano 2b45e8
	  }
kusano 2b45e8
	}
kusano 2b45e8
      }
kusano 2b45e8
#else
kusano 2b45e8
      for (j = 0; j < nn; j ++) {
kusano 2b45e8
	for (i = j; i < nn; i ++) {
kusano 2b45e8
	  c[(i + loop + (j + loop) * ldc) * 2 + 0] +=
kusano 2b45e8
	    subbuffer[(i + j * nn) * 2 + 0] + subbuffer[(j + i * nn) * 2 + 0];
kusano 2b45e8
	  if (i != j) {
kusano 2b45e8
	    c[(i + loop + (j + loop) * ldc) * 2 + 1] +=
kusano 2b45e8
	      subbuffer[(i + j * nn) * 2 + 1] - subbuffer[(j + i * nn) * 2 + 1];
kusano 2b45e8
	  } else {
kusano 2b45e8
	    c[(i + loop + (j + loop) * ldc) * 2 + 1]  = ZERO;
kusano 2b45e8
	  }
kusano 2b45e8
	}
kusano 2b45e8
      }
kusano 2b45e8
#endif
kusano 2b45e8
    }
kusano 2b45e8
    
kusano 2b45e8
#ifdef LOWER
kusano 2b45e8
    GEMM_KERNEL(m - mm - nn, nn, k,
kusano 2b45e8
		  alpha_r,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		  alpha_i,
kusano 2b45e8
#endif
kusano 2b45e8
		  a + (mm + nn) * k * COMPSIZE, b + loop * k * COMPSIZE, 
kusano 2b45e8
		  c + (mm + nn + loop * ldc) * COMPSIZE, ldc); 
kusano 2b45e8
#endif
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
    return 0;
kusano 2b45e8
}