time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

bb_t.c (2319B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2020 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 #include "stdlib/strided/base/binary/bb_t.h"
     20 #include "stdlib/strided/base/binary/typedefs.h"
     21 #include "stdlib/strided/base/binary/macros.h"
     22 #include <stdint.h>
     23 
     24 /**
     25 * Applies a binary callback accepting and returning unsigned 8-bit integers to unsigned 8-bit integer strided input arrays, casts the callback's unsigned 8-bit integer return value to an unsigned 16-bit integer, and assigns results to elements in an unsigned 16-bit integer strided output array.
     26 *
     27 * @param arrays   array whose first two elements are pointers to strided input arrays and whose last element is a pointer to a strided output array
     28 * @param shape    array whose only element is the number of elements over which to iterate
     29 * @param strides  array containing strides (in bytes) for each strided array
     30 * @param fcn      callback
     31 *
     32 * @example
     33 * #include "stdlib/strided/base/binary/bb_t.h"
     34 * #include <stdint.h>
     35 *
     36 * // Create underlying byte arrays:
     37 * uint8_t x[] = { 0, 0, 0 };
     38 * uint8_t y[] = { 0, 0, 0 };
     39 * uint8_t out[] = { 0, 0, 0, 0, 0, 0 };
     40 *
     41 * // Define a pointer to an array containing pointers to strided arrays:
     42 * uint8_t *arrays[] = { x, y, out };
     43 *
     44 * // Define the strides:
     45 * int64_t strides[] = { 1, 1, 2 }; // 1 byte per uint8, 2 bytes per uint16
     46 *
     47 * // Define the number of elements over which to iterate:
     48 * int64_t shape[] = { 3 };
     49 *
     50 * // Define a callback:
     51 * uint8_t add( uint8_t x, uint8_t y ) {
     52 *     return x + y;
     53 * }
     54 *
     55 * // Apply the callback:
     56 * stdlib_strided_bb_t( arrays, shape, strides, (void *)add );
     57 */
     58 void stdlib_strided_bb_t( uint8_t *arrays[], int64_t *shape, int64_t *strides, void *fcn ) {
     59 	BinaryFcnUint8 *f = (BinaryFcnUint8 *)fcn;
     60 	STDLIB_STRIDED_BINARY_LOOP_CLBK( uint8_t, uint16_t )
     61 }