Does boost::multiprecision have make_signed_t? - boost-multiprecision

How to by a given unsigned integer type that can be uint128_t, uint256_t, uint512_t ... define signed type with the same precision?
With a pseudo-code I need something like this:
using UInt = boost::multiprecision::uint128_t;
using Int = boost::multiprecision::make_signed_t<UInt>;
static_assert(std::is_same_v<Int, boost::multiprecision::int128_t>);

Related

How to add write_raw function in my iio_info structure

I am writing a driver using iio framework. So far it goes well. All the inputs and sysfs entries are working perfectly and the values measured are fine. (It is very well documented and it is easy). But I need a small extension to be able to write on one of the channels. When I add my function in iio_info the compiler issues me an error:
drivers/iio/adc/iio-ccuss.c:197:15: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
.write_raw = ccuss_iio_write_raw,
^~~~~~~~~~~~~~~~~~~
It is very weird for me. I even can't believe I am asking shamelessly this here but I am very frustrated. I lost almost half day with that.
My structure is:
static const struct iio_info ccuss_iio_info = {
.driver_module = THIS_MODULE,
.attrs = &ccuss_iio_attribute_group,
.read_raw = ccuss_iio_read_raw,
.write_raw = ccuss_iio_write_raw,
};
my channel types are IIO_VOLTAGE, IIO_TEMP and IIO_HUMIDITYRELATIVE.
I am start thinking to make it as an device attribute :-( if I do not receive an answer in the next 12 hours.
Update:
just to be more visible, according Murphy's comment.
static int ccuss_iio_write_raw(struct iio_dev *iio,
struct iio_chan_spec const *channel, int *val1,
int *val2, long mask);
P.S. I do not want to remove this error by the most known way. The QA (and me) will be unhappy.
Thanks
According to the reference the write_raw() function is declared as follows:
int (*write_raw)(
struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val,
int val2,
long mask);
Your implementation is declared like this:
static int ccuss_iio_write_raw(
struct iio_dev *iio,
struct iio_chan_spec const *channel,
int *val1,
int *val2,
long mask);
So you declare the two integer parameters as pointers, but they are expected to be passed by value. I think that's the mismatch that causes the "incompatible pointer type" error.

How to use macros to replace/inject function calls in OpenCL

I am developing an algorithm using PyOpenCL. To avoid code duplication I am trying to use templating along with C macros to replace function calls, since OpenCL 1.2 does not support function pointers.
I currently have the following macro section in my OpenCL kernel code:
#define LINEAR_FIT_SEARCH_METHOD ${linear_fit_search_method}
#if LINEAR_FIT_SEARCH_METHOD == MIN_MAX_INTENSITY_SEARCH
#define LINEAR_FIT_SEARCH_METHOD_CALL() determineFitUsingMinMaxIntensitySearch(lineIntensities,imgSizeY,linFitParameter,linFitSearchRangeXvalues)
#elif LINEAR_FIT_SEARCH_METHOD == MAX_INCLINE_SEARCH
#define LINEAR_FIT_SEARCH_METHOD_CALL() determineFitUsingInclineSearch(lineIntensities,imgSizeY,linFitParameter,linFitSearchRangeXvalues,inclineRefinementRange)
#endif
In the kernel code I also define the corresponding functions determineFitUsingMinMaxIntensitySearch and determineFitUsingInclineSearch. I am now attempting to use the macro to exchange the function call like this:
__private struct linearFitResultStruct fitResult = LINEAR_FIT_SEARCH_METHOD_CALL();
so that I select the desired call (note: I always only need either one or the other and configuration is done before the program runs (no need for dynamically switching the two)).
Using PyOpenCL templating I now do something like this:
def applyTemplating(self):
tpl = Template(self.kernelString)
if self.positioningMethod == "maximumIntensityIncline":
linear_fit_search_method="MAX_INCLINE_SEARCH"
if self.positioningMethod == "meanIntensityIntercept":
linear_fit_search_method="MIN_MAX_INTENSITY_SEARCH"
rendered_tpl = tpl.render(linear_fit_search_method=linear_fit_search_method)
self.kernelString=str(rendered_tpl)
Where self.kernelString contains the macro above along with the code.
Unfortunately I am getting this error, which I do not understand:
1:455:53: error: implicit declaration of function 'determineFitUsingInclineSearch' is invalid in OpenCL
1:9:41: note: expanded from macro 'LINEAR_FIT_SEARCH_METHOD_CALL'
1:455:41: error: initializing 'struct linearFitResultStruct' with an expression of incompatible type 'int'
1:536:30: error: conflicting types for 'determineFitUsingInclineSearch'
1:455:53: note: previous implicit declaration is here
1:9:41: note: expanded from macro 'LINEAR_FIT_SEARCH_METHOD_CALL'
1:616:41: error: initializing 'struct linearFitResultStruct' with an expression of incompatible type 'int'
I have very little experience with macros so:
Is what I am attempting even possible in this way or do I need to go a different route?
UPDATE 1:
This code runs fine when I set self.positioningMethod = "meanIntensityIntercept" in my unit test, but fails when setting self.positioningMethod = "maximumIntensityIncline" with the error message above. I cannot spot the error at the yet.
UPDATE 2:
I was also inspired by this post, if that helps:
how to compare string in C conditional preprocessor-directives
As you say you have very little experience with macros then I would go for something simple. determineFitUsingMinMaxIntensitySearch and determineFitUsingInclineSearch accept different number of arguments, so this could done this way:
kernel_code = """
#ifdef USE_FUNCTION_A
void function_a(
int x,
int y,
int extra_param,
__global const int* restrict in,
__global int* restrict out
)
{
//...
}
#else
void function_b(
int x,
int y,
__global const int* restrict in,
__global int* restrict out
)
{
//...
}
#endif
__kernel void my_kernel(
int x,
int y,
__global const int* restrict in,
__global int* restrict out
)
{
// ...
#ifdef USE_FUNCTION_A
function_a(x,y,5,in,out);
#else
function_b(x,y,in,out);
#endif
// ...
}
"""
if use_function_a:
prg = cl.Program(ctx, kernel_code).build("-DUSE_FUNCTION_A")
else:
prg = cl.Program(ctx, kernel_code).build("")

MFC Classes CMAP

What I do not understand is the : “UINT&”. What does it mean in the context of the template
static CMap<CString, LPCSTR, UINT, UINT&> cXMLfields::fields_by_name;
static CMap<CString, LPCSTR, UINT, UINT&> cXMLfields::oopf_fields_by_name;
static CString friendly_name[XML_FIELDNUM];
static CString fields_by_id[XML_FIELDNUM];
static CString oopf_fields_by_id[OOPF_XML_FIELDNUM];
static void Build_map();
static void MoveItem(CListBox& src, CListBox& dst, int index);
CMap<CString,LPCTSTR, struct_sample,struct_sample> myMap;
struct_sample aTest;
aTest.a = 1;
aTest.b = 2;
aTest.c = 3;
myMap.SetAt("test",aTest);
struct_sample aLookupTest;
BOOL bExists = myMap.Lookup("test",aLookupTest); //Retrieves the
//struct_sample corresponding to "test".
I understand the theory, but my key is a String e.g “RFIDTAG1”.And my value is an unsigned integer. Example.UNIT is the Value to the Specific KEY ...for example {Age : 27} Where Age is the Key and 27 is the Value.I struggle when the value is an integer, I can understand if the value was a structure.So Can you use {Age: 27 } as the example and show me the code like below when using a structure
The & means pass by reference.
See this link.
Also here on MSDN.
ARG_VALUE
Data type used for VALUE arguments; usually a reference to VALUE.

Any way to pass enum values by name as commandline args?

Is there any way to pass the value of an enum by name from the commandline? Rather what's the cleanest solution?
I tried the below,
typedef enum int unsigned { white, black, red } colour_e;
class house;
rand colour_e colour;
string n_colour = "white";
constraint c_colour {
colour.name() == n_colour;
}
endclass: house
program top;
house paradise;
initial begin
paradise = new();
void'($value$plusargs("colour=%0s", paradise.n_colour));
if (!paradise.randomize())
$display("not randomized");
else
$display("paradise.colour = %s",paradise.colour);
end
endprogram: top
I would want to pass something like this +colour=black. so that the paradise.colour is assigned black.
vcs cribbed for using enum.name() in the constraints.
below is the error.
Error-[NYI-CSTR-SYS-FTC] NYI constraint: sys function calls
T-enum_1.sv, 9 $unit, "this.colour.name" System function calls are
not yet implemented in constraints. Remove the function call or if
possible replace it with an integral state variable assigned in
pre_randomize().
while Riviera cried as below
ERROR VCP7734 "Type of 'this.colour.name()' is not allowed in a
constraint block. Only integral types are allowed in a constraint
block." "design.sv" 9 1 ERROR VCP7734 "Type of 'n_colour' is not
allowed in a constraint block. Only integral types are allowed in a
constraint block." "design.sv" 9 1 WARNING VCP7114 "STRING value
expected for format specifier %s as parameter
paradise.colour." "testbench.sv" 13 54
which brings the question to me, does everything in the contraint block has to be of integral type (just like we cannot declare a string as rand variable)?
ANyone wants to play around the code please have a look at the code at EDA playground here
Use uvm_enum_wrapper class to do the conversion from string to corresponding enum value. It is a template class wrapper defined in uvm_globals.svh (part of UVM 1.2) and you can use it as follows:
typedef enum {white, black, red} colour_e;
typedef uvm_enum_wrapper#(colour_e) colour_wrapper;
string colour_str;
void'($value$plusargs("colour=%0s", colour_str));
colour_wrapper::from_name(colour_str, paradize.n_colour);
The wrapper class uvm_enum_wrapper works by traversing the enum entries and creating an assoc array for a enum[string] map for the given enum type (supplied as template parameter). For more details take a look at the documentation.
There is another solution for the same. If you are not using UVM 1.2 version then there is like you can take string as an input argument and convert that string argument into int type. After that you can directly cast int to enum type by $cast.
Because there is no way to convert string to enum type (except UVM 1.2) so you have to add one extra step for the same.
module Test;
typedef enum {black,red,blue} color_e; //enum declaration
color_e color; //type of enum
string cmd_str; //Commandline string input
int cmd_int; //Input string is first converted into int
initial
begin
$value$plusargs("enum_c=%0s",cmd_str); //Take input argument as string it may be 0,1 or 2
cmd_int=cmd_str.atoi(); //Now convert that string argument into int type
$cast(color,cmd_int); //Casting int to enum type
$display("Value of color is --> %p",color); //Display value of enum
end
endmodule

difference between static T const and static const T

Assuming that T is an arbitrary type and we're talking about Objective-C. Then what is the difference between
static T const x = ....
and
static const T x = ....
?
They are the same.
A little background about const:
Objective-C, just like C, uses the Clockwise/Spiral Rule. In a case where you have only modifiers at the left side of the variable (of foo) you read stuff going from right to left:
int * const * var;
is read: var is a pointer to a constant pointer to integer.
However const has the same effect when it's before or after the first type:
int const var; // constant integer
const int var; // constant integer, same as above
static, instead, affects the whole variable: it's the variable to be static, not the element pointed by it or anything else: a pointer to integer can be used both to point to a static integer, or to an automatic integer without distinction, and C doesn't provide a syntax to declare a pointer able to point to static variables (or to automatic variables) only.
static int * x; // x is a static pointer to integer
int static * y; // as above y is a static pointer to integer
int * static z; // THIS SYNTAX IS NOT ALLOWED
// but if it was, it would mean the same thing
For this reason I prefer to place it before any const modifier, but it doesn't actually matter.
static const int * const * x; // this is what I do
I believe the distinction is only important for pointer types; for example 'char *'.
const char *p means that the buffer pointed to by p cannot be updated but pointer p itself can be changed (typically incremented with p++), for example:
void f(const char *p)
{
while (*p != '\0')
{
putc(*p);
p++;
}
}
char * const p means that the buffer pointed to by p can be updated but pointer p cannot be changed.
EDIT Thanks for JeremyP for the following comment:
It's quite common in Apple's APIs to define string constants (instead of using #defines), especially if the string is an NSString i.e. NSString * const kFoo = #"bar";