1 /*
   2  * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "jni.h"
  27 #include "AlphaMath.h"
  28 
  29 JNIEXPORT unsigned char mul8table[256][256];
  30 JNIEXPORT unsigned char div8table[256][256];
  31 
  32 void initAlphaTables()
  33 {
  34     unsigned int i;
  35     unsigned int j;
  36 
  37     for (i = 1; i < 256; i++) {                 /* SCALE == (1 << 24) */
  38         unsigned int inc = (i << 16) + (i<<8) + i;       /* approx. SCALE * (i/255.0) */
  39         unsigned int val = inc + (1 << 23);              /* inc + SCALE*0.5 */
  40         for (j = 1; j < 256; j++) {
  41             mul8table[i][j] = (val >> 24);      /* val / SCALE */
  42             val += inc;
  43         }
  44     }
  45 
  46     for (i = 1; i < 256; i++) {
  47         unsigned int inc;
  48         unsigned int val;
  49         inc = 0xff;
  50         inc = ((inc << 24) + i/2) / i;
  51         val = (1 << 23);
  52         for (j = 0; j < i; j++) {
  53             div8table[i][j] = (val >> 24);
  54             val += inc;
  55         }
  56         for (j = i; j < 256; j++) {
  57             div8table[i][j] = 255;
  58         }
  59     }
  60 }