How to do inline assembly with cc

Hi,
i was looking for information on how to exactly formulate inline-assembly statements with the c compiler. However there were no usefull information available. Can you please point me to some locations, please.
matthias

There is basic inline assembler, which looks like:
asm("assembler instruction here");
You can try much more advanced gcc-style inline assembler with cc/CC, starting from Express 3.
It is not fully implemented though, so you should restrict yourself to very basic constructs only.
It works better on Sparc than on Intel. And you better compile with optimization...
regards,
__Fedor.

Similar Messages

  • How to add inline TVF with dynamic columns from CRL Dynamic Pivot

    Hi I am trying to implement the code in the following article.
    SQLServerCentral Aricle
    Now, I've pushed the assembly to my DB and can see it there. 
    So far I have tried building an Inline TVF, as I assume this is how it would be used on the DB; however, I am receiving the following error on my code, I must
    be missing a step somewhere, as I've never done this before. I'm lost on how to implement this clr function on my db?
    Create Function script:
    CREATE FUNCTION clrDynamicPivot
    @query nvarchar(4000),
    @pivotColumn nvarchar(4000),
    @selectCols nvarchar(4000),
    @aggCols nvarchar(4000),
    @orderBy nvarchar(4000)
    RETURNS TABLE
    AS
    return
    (external NAME CLRfunctions.RIFunctions.clrDynamicPivot)
    GO
    Error:
    Msg 156, Level 15, State 1, Procedure clrDynamicPivot, Line 18
    Incorrect syntax near the keyword 'external'.
    public static void CreateTempTable(SqlString query)
                using (SqlConnection sqlconn = new SqlConnection("Context Connection=True"))
                    SqlCommand sqlCmd = sqlconn.CreateCommand();
                    sqlCmd.CommandText = query.ToString();
                    sqlconn.Open();
                    sqlCmd.ExecuteNonQuery();
     public static string GetPivotData(string pivotColumn)
                string stmt = string.Format("select distinct {0} from #temp", pivotColumn);
                string pivotCols = string.Empty;
                using (SqlConnection cn = new SqlConnection("Context Connection=True"))
                    SqlCommand cmd = cn.CreateCommand();
                    cmd.CommandText = stmt;
                    cn.Open();
                    using (SqlDataReader dr = cmd.ExecuteReader())
                        while (dr.Read())
                            if (dr.GetFieldType(0) == typeof(System.Int32))
                                pivotCols += "[" + dr.GetInt32(0) + "],";
                            if (dr.GetFieldType(0) == typeof(System.Decimal))
                                pivotCols += "[" + dr.GetDecimal(0) + "],";
                            if (dr.GetFieldType(0) == typeof(System.String))
                                pivotCols += "[" + dr.GetString(0) + "],";
                return pivotCols.Remove(pivotCols.Length - 1);
    [Microsoft.SqlServer.Server.SqlProcedure(Name="clrDynamicPivot")]
    public static void clrDynamicPivot(SqlString query, SqlString pivotColumn, SqlString selectCols, SqlString aggCols, SqlString orderBy)
        string stmt = string.Empty;
        try
           CreateTempTable(query);
           string pivot = GetPivotData(pivotColumn.ToString());
           stmt = string.Format("select * from ( select {0} from #temp ) as t pivot ( {1} for {2} in ( {3} )) as p {4}",
           selectCols.ToString(),
           aggCols.ToString(),
           pivotColumn.ToString(),
           pivot,
           orderBy.ToString());
           using (SqlConnection cn = new SqlConnection("Context Connection=True"))
              SqlCommand cmd = cn.CreateCommand();
              cmd.CommandText = stmt;
              cn.Open();
              SqlDataReader reader = cmd.ExecuteReader();
              SqlContext.Pipe.Send(reader);
         catch (Exception ex)
           throw new Exception(string.Format("clrDynamicPivot Error stmt:{0}", stmt), ex);
    DECLARE @query nvarchar(4000)
    DECLARE @pivotColumn nvarchar(4000)
    DECLARE @selectCols nvarchar(4000)
    DECLARE @aggCols nvarchar(4000)
    DECLARE @orderBy nvarchar(4000)
    set @query = 'select PayMethod, datepart(hh, OrderDate) as OrderHour, ProductTotal into #temp from dbo.Orders (nolock) where OrderDate between getdate()-1 and getdate() and division = ''15'''
    set @pivotColumn = 'PayMethod'
    set @selectCols = 'PayMethod, OrderHour, ProductTotal'
    set @aggCols = 'sum(ProductTotal)'
    set @orderBy = ''
    EXECUTE dbo.clrDynamicPivot
    @query
    ,@pivotColumn
    ,@selectCols
    ,@aggCols
    ,@orderBy
    GO

    You can't build an inline TVF in SQLCLR, only (the equivalent of) multi-statement TVFs and scalar functions. And the SQLCLR code for multi-statement TVFs must be coded with a specific pattern, see
    https://msdn.microsoft.com/en-us/library/ms131103.aspx.
    Looking at the example you reference, it was implemented as a SQLCLR stored procedure.
    Cheers, Bob
      

  • Problem with gcc-like inline assembly in cc

    Hi,
    I am trying to compile the following code for a sparc machine using sun studio 12.
    #define MAGIC(n)  asm("sethi %0, %%g0" : :"g"(n));
    int main(int argc, char **argv)
            int x=1;
            MAGIC(x);
            return 0;
    }I am using the following command:
    cc -xO3 -xtarget=ultra2 -m32 -xarch=sparcvis -xregs=no%appl -w test.c -o test
    and I get the following error:
    cg error (as) : "__gnu_asm_inline_fake_test.c (template for __gnu_asm_inline_temp_func_001)", line 1 : statement syntax
    cc: cg failed for test.c
    Isn't Sun cc supposed to support gcc-like inline assembly? If so, what is the problem with the code above?
    Thanks in advance,
    Nick

    Hi,
    we have the same Problem with the inline assembler. We are using Sunstudio 12 on x86 and tried to get this code compiled (Sunstudio 12 should be gas compatible).
    any ideas ?
    thanks
    Dieter
    #define HEC_HTONF(x) \
    (__extension__ \
    register HVB::float32_t __v, __x = (x); \
    __asm__ ( \
    "bswap %0" \
    : "=r" (__v) \
    : "0" (__x) \
    __v; \
    #define HEC_HTONLF_INPLACE(x) \
    __asm__ ( \
    "leal %0, %%ecx \n\t" \
    "movl (%%ecx), %%eax \n\t" \
    "movl 4(%%ecx), %%edx \n\t" \
    "bswap %%eax \n\t" \
    "bswap %%edx \n\t" \
    "movl %%eax, 4(%%ecx) \n\t" \
    "movl %%edx, (%%ecx) \n\t" \
    : "=m" (x) \
    : "m" (x) \
    : "%eax", "%ecx", "%edx" \
    );

  • WS6U2: external inline assembler templates: optimising bug with %fsr

    I have the following code in an external inline assembler template file:
    ! double fpop_eval_FADDd(const double*,const double*,unsigned long long*);
         .inline fpop_eval_FADDd,3
         ldx     [%o2], %fsr
         ldd     [%o0], %f0
         ldd     [%o1], %f2
         faddd     %f0, %f2, %f0
    !     .volatile
         stx     %fsr, [%o2]
    !     .nonvolatile
         .end
    If I compile a C++ function that calls fpop_eval_FADDd() which is complicated enough (which I won't include here) with optimisation on (-xO1), then the "stx %fsr, [%o2]" gets optimised away (perhaps the code-generator doesn't realise that faddd has the side-effect of changing %fsr).
    If I remove the comments (!) in front of the .volatile and .nonvolatile (or I compile without optimisation on) then it doesn't optimise it away (which is what I want). in fact it doesn't optimise the inline template and the calling function at all (which is not what I want)!
    [btw.  is there a bug report page for Forte C/C++?  I've found one for Forte for Java, but I haven't found one for Forte C/C++]

    I am getting this same issue. Did you ever find a fix for this?

  • Need inline assembly help

    How do I get the long long in %eax , %edx into a local variable that I can reference in C++??
    typedef unsigned long long tsc_t;
    extern inline tsc_t rdtsc() {
    asm("rdtsc");
    asm("movl %eax,-8(%ebp)");
    asm("movl %edx,-4(%ebp)");
    I am following the ABI by returning the double double on the stack. However the compiler (Forte 6 Update 1) complains that this function does not return a value. I tried delcaring a tsc_t stack variable, hoping that the movl operation to the stack would coincide with the location of the stack variable and returning the variable, but it does not work.
    Does anyone know where to find a reference on how Forte implemented their inline assembly.
    This exact same inline function works great using gcc! Gcc also has extensive documentation on inlining.
    Any help is appreciated.

    Hi there,
    The asm directive is not well supported in C++.
    There is no way to refer to a local variable by name in an asm directive. In addition, asm statements conflict with optimization. You are better off writing a routine entirely in assembler and assembling it into a .o, and calling the routine from a C++ function.
    If you are working on SPARC architecture based compiler ( not x86), then you can use .il templates and that is a preferable over the asm("") syntax.
    ....jagruti
    Developer Technical Support
    Sun Microsystems Inc.

  • Question -  how i can prevent assembly order rescheduling when in VA02 ?

    Hi                                             ( ECC 6.0)
    I am working with assembly orders.  In sales order create - the system creates an assembly order - requirements type = dynamic order.
    If i amend the sales order a few days later - the system reschedules the assembly order - even when the assembly order is started and has status REL = released.  I get error CO061 - start date in past.. as the system first backwards reschedules and then reschedules forwards.
    Question -  any ideas how i can prevent assembly order rescheduling when in sales order change VA02 ? I need the system  to check the production order status and if = REL then prevent the rescheduling.  Putting a change block on the production order does not work as it ultimately breaks the link between sales:assembly order.
    I am thinking i need to use an SD user exit to read the assembly order and prevent order changes if the assembly order is = REL.
    thanks in advance
    Graham.

    Hi Ram
    We are using dynamic link.  My original solution was to set the 'nochange' on release- however if the sales order qty changed - or the dates changed - or indeed any ATP check was performed - the link was sometimes lost - dependant on user keystrokes.  VA02 still calls assembly order change in this scenario - and the user gets the mesage that no change is present - and ATP returns 0 qty.
    What I think i can use is user exit  EXIT_SAPLCOEXT_001 in conjunction with a user status.  I plant to set the status 'block' on release - although configure it to have no action.  In the user exit - called in the interface between sales / assembly order - I plan to check the assembly order for this status and set the error condition if the status is set.  In debug mode - setting the eror manually - this appears to work as the system never calls assembly order change and accepts the assembly order date/qty as 'supply' in the atp check.
    thanks for you assistance.
    regards
    Graham

  • (x86) Inline assembler syntax errors for 8bit variables

    Hello,
    I am porting some gcc code to Solaris and have some issues
    with the inline assembler. It works reasonably well on most of
    my code but with some instructions I have difficulties.
    In gcc, when I declare a variable as char/unsigned char and
    reference it within an asm-statement the assembler will generate
    'half'-register names for it (e.g. %al, %cl, ...).
    sunCC generates full registers for these variables and so
    certain instructions fail to assemble.
    e.g.
    char flag;
    asm ("setz %0" : "=q"(flag) : :);
    Syntax error is given then for:
    "setz %eax"
    Is there a way to force the use of 8bit registers?
    --L                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Even worse:
    char flag, char* ptr;
    asm("xchgb %0, %1" : "=q"(flag),"=m"(*ptr):"0"(1), "m"(*ptr):);
    produces
    xchgb %edx,(%eax)
    on sunCC even when no "-O" flag is given.
    But
    char flag, char* ptr;
    flag = 1;
    asm("xchgb %0, %1" : "=q"(flag),"=m"(*ptr):"0"(flag),"m"(*ptr):);
    produces
    xchgb %dl,(%eax)
    on sunCC if no "-O" flag is given.
    Strange behaviour indeed... :/
    --L                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How do I re-assemble two halves of a large scanned photo to create the original picture in CS3

    How do I re-assemble two halves of a large scanned photo to create the original picture in CS3

    Good day!
    Is there overlap between the scans?
    If so File > Automate > Photomerge might be enough, otherwise you can load both images in one document and manually align/distort them and address color/brightness-diferences with Adjustment Layers.
    Regards,
    Pfaffenbichler

  • Inline popup with css

    Hi,
    I want to apply css for inline popup.
    I gave below styles
    af|panelWindow::header{
    background-image: none;
    background-color:#58585A;
    af|panelWindow::header-start{
    background-image: none;
    background-color:#58585A;
    If I give above styles its applying for all panel window. But I don't want it. I tried with multiple skin approach its also not working.
    I want to apply for inline popup which I selected through taskflow.
    In taskflow, I gave Run as Dialog as true and Display type is inline-popup.
    Here, How do I give styles for inline- popup while coming inline-popup?.
    please , Help me
    Thanks in advance. :)

    Hi,
    How can apply multiple skin with oracle adf ? that was I asked..
    JDeveloper : 11.1.1.6
    pls help me...
    Edited by: 960539 on Sep 23, 2012 10:11 PM

  • How to combine 2 assembly files????

    Is anybody how to combine 2 assembly files together??? the 2 assembly files are the generated codes of 2 different c files. Each c file has its own main function. ThANKS

    Is anybody how to combine 2 assembly files together???
    the 2 assembly files are the generated codes of 2
    different c files. Each c file has its own main
    function. ThANKSYou're so wrong, on so many levels.... where to begin....
    This is a Java forum, not assembly.... the two languages couldn't be more different.
    You should at least have posted the question to "Native Methods".
    Also, what you say doesn't make sense.
    C functions compile to generate "object code", ie. *.obj.
    These are then "Linked" together, what a program called a linker.
    If you actually do have "assembly language" source code, ie. in an *.asm file, then you use an assembler
    to assemble it.... again to an object file *.obj. Then use a linker to link it.
    My use of the phrase "object file" does not have anything to do with "object oriented programming".
    regards,
    Owen

  • How can I do this with automator, shouldent be to hard right?

    I am not new to the programming world but new to apple, however, i wanted to know if this was possible or not ;
    Id like to run a script that will ultimatly do this
    1)Run Safari
    2) Open brokerage website
    3) Log In (using key chain or by apple script inputing the user name and password or asking me for dialog box
    4)click a certain link somewhere on the page that will pop up the streaming quotes section
    5) minimize all safari windows expect the one that is streaming the quotes
    6) keep clicking a link that refreshes every half hour the account page so it dosent log me out
    should be doable right? Any tips for a first time user for apple script? I read some of what it can do and how its done, (iv programmed with C++ and visual basic) and apple script seems to be really simple, however I dont want to under or over estimate its abbilites.
    Any input MUCH appricated.

    m_oody,
    Good, and I can see that we are thinking along the same lines with regards to other applications for it.
    I am a little confused as to why you had to comment out the "on run". I set this script up so that you can already run it as an AppleScript or an Automator action. The "on run" and "end run" pairing are assumed in simple AppleScripts that only have a single routine but, in my opinion, should really be included for good programming style.
    Run as AppleScript
    Compile, save and run as it is without commenting out anything. You can add further calls to activities, like you mentioned, in the main "on run" routine, and the required GUI commands with other subroutines.
    Within the main "on run" routine is where you could call subroutines that would open up other windows or tabs with other sites using Safari, other browsers, and other net applications such as RSS readers, Internet radio, etc.
    Run as Automator action
    You are right that there are currently a limited selection of actions available with which to build a workflow. However, Apple did leave enough flexibility through actions with calls to AppleScript ("Run AppleScript"), a Unix Shell script ("Run Shell Script"), run other Automator workflows ("Run Workflow")and, Web Services ("Run Web Service") to provide extensibility to the application. Of course there is also a tremendous flexibility within Unix itself with all the scripting and full programming languages that can be run through the Shell.
    Long winded today!
    Here is what needs to be done to run this as an Automator action.
    1) Open Automator and look for an action called "Run AppleScript" which is within the "Automator" category of actions.
    2) Drag it over to the workflow assembly line. You will notice it contains the core of an AppleScript main routine.
    3) Normally when you are building these routines you build them within this environment and test them there and only replace the text labelled "(* Your script goes here *)". However, in our case it was build in the AppleScript Script Editor environment and because the Properties section must go at the top we need to modify its structure for it to run properly and fit into a workflow that consists of more than this one action. So here is what you need to do:
    a) Go to Script Editor and either delete the line entirely or comment out the line by putting the "--" characters in front of the "on run {}" line. I usually just comment the line out so that if I need to work with it in AppleScript again it is easy to do.
    b) Remove the comment characters from "on run {input,parameters}" and "return input". These lines are required to accept and pass on info within the workflow.
    c) Select all of the text in the script and copy it to the clipboard.
    d) Move over to Automator, select all of the text in the "Run AppleScript" action, and paste in the new script.
    It should now compile if you press the hammer icon and run if you press either the green arrow icon on the action or the overall workflow run icon.
    You now have the option of saving it as:
    1) Basic Workflow, requiring Automator to be running
    2) Application, free of Automator running
    3) Various plug-ins including one for iCal alarms which you could use for your automated morning download. Search for plug-ins in the Help of Automator for more information.
    Once it is saved as an alarm you just need to set up a schedule for running it in iCal, attach the alarm by using the "Open File" alarm, and watch the action.
    The AppleScript can also be run with an alarm in iCal. In that case you attach the alarm using the "Run Script" alarm.
    PowerBook 12" Mac OS X (10.4.6)

  • Inlining assembly templates: bugs in libm.il?

    the man-page for inline(1) states that:
    An inline-directive is a command of the form:
    .inline identifier, argsize
    This declares a block of code for the routine named by identifier, with argsize bytes of arguments.
    note: "argsize _bytes_ of arguments".
    now all of the inline assembly templates in WS6U2 (e.g., WS6U2/lib/v8plusa/libm.il and WS6U2/lib/v9a/libm.il) seem to interpret argsize as being the number of registers, not the number of bytes. e.g., the sqrt function in the above two files are:
    v8plusa:
         .inline     sqrt,2
         std     %o0,[%sp+0x48]          ! store to 8-aligned address
         ldd     [%sp+0x48],%f0
         fsqrtd     %f0,%f0
         .end
    v9a:
         .inline     sqrt,1
         fsqrtd     %f0,%f0
         .end
    when according to the man-page, the argsize for both should be 8 (sizeof(double)). [note: the v9a function is using the 64-bit calling convention where fp args go in the fp registers; this is not mentioned in the inline man-page, and it probably ought to be].
    the VIS SDK interprets argsize to be the number of bytes; e.g., vis_64.il contains this:
    ! double vis_fmul8x16(float /*frs1*/, double /*frs2*/);
    .inline vis_fmul8x16,12
    fmul8x16 %f1,%f2,%f0
    .end
    it probably doesn't matter for small numbers of arguments (maybe one or two) but it is confusing to have different interpretations in the same product. perhaps it could confuse the optimiser too?
    can anyone clear this up?

    Sorry about the delay, it took some time to find the right people to ask. Nice question.
    Here's what I got.
    Here is the official answer:
         The count parameter is silently ignored. It
         remains in the files due to the pre-SC5.0
         compiler used it. Prior to SC5.0 the inliner
         required a numeric argument whose value was
         ignored. It's best to supply an argument
         count, even if it's 0.
    Hope this helps,
    Paul

  • How can i use assembly instructions?

    Hello Friends,
    i wanna use assembly code in java to reach hardware in java.But i don't how i can put assembly code into java code blocks.Can u help?

    You can't put assemply code in java. You've got to use c code with assemply instructions through jni

  • How to create a node with attributes at runtime in webdynpro for ABAP?

    Hi Experts,
             How to create a node with attributes at runtime in webdynpro for ABAP? What classes or interfaces I should use? Please provide some sample code.
    I have checked IF_WD_CONTEXT_NODE_INFO and there is ADD_NEW_CHILD_NODE method. But this is not creating any node. I this this creates only a "node info" object.
    I even check IF_WD_CONTEXT_NODE but i could not find any method that creates a node with attribute.
    Please help!
    Thanks
    Gopal

    Hi
       I am getting the following error while creating a dynamic context node with 2 attributes. Please help me resolve this problem.
    Note
    The following error text was processed in the system PET : Line types of an internal table and a work area not compatible.
    The error occurred on the application server FMSAP995_PET_02 and in the work process 0 .
    The termination type was: RABAX_STATE
    The ABAP call stack was:
    Method: IF_WD_CONTEXT_NODE~GET_STATIC_ATTRIBUTES_TABLE of program CL_WDR_CONTEXT_NODE_VAL=======CP
    Method: GET_REF_TO_TABLE of program CL_SALV_WD_DATA_TABLE=========CP
    Method: EXECUTE of program CL_SALV_WD_SERVICE_MANAGER====CP
    Method: APPLY_SERVICES of program CL_SALV_BS_RESULT_DATA_TABLE==CP
    Method: REFRESH of program CL_SALV_BS_RESULT_DATA_TABLE==CP
    Method: IF_SALV_WD_COMP_TABLE_DATA~MAP_FROM_SOURCE_DATA of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMP_TABLE_DATA~MAP_FROM_SOURCE of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMP_TABLE_DATA~UPDATE of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_VIEW~MODIFY of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMPONENT~VIEW_MODIFY of program CL_SALV_WD_A_COMPONENT========CP
    My code is like the following:
    TYPES: BEGIN OF t_type,
                CARRID TYPE sflight-carrid,
                CONNID TYPE sflight-connid,
             END OF t_type.
      Data:  i_struc type table of t_type,
      dyn_node   type ref to if_wd_context_node,
      rootnode_info   type ref to if_wd_context_node_info,
      i_node_att type wdr_context_attr_info_map,
      wa_node_att type line of wdr_context_attr_info_map.
          wa_node_att-name = 'CARRID'.
          wa_node_att-TYPE_NAME = 'SFLIGHT-CARRID'.
          insert wa_node_att into table i_node_att.
          wa_node_att-name = 'CONNID'.
          wa_node_att-TYPE_NAME = 'SFLIGHT-CONNID'.
          insert wa_node_att into table i_node_att.
    clear i_struc. refresh i_struc.
      select carrid connid into corresponding fields of table i_struc from sflight where carrid = 'AA'.
    rootnode_info = wd_context->get_node_info( ).
    rootnode_info->add_new_child_node( name = 'DYNFLIGHT'
                                       attributes = i_node_att
                                       is_multiple = abap_true ).
    dyn_node = wd_context->get_child_node( 'DYNFLIGHT' ).
    dyn_node->bind_table( i_struc ).
    l_ref_interfacecontroller->set_data( dyn_node ).
    I am trying to create a new node. That is
    CONTEXT
    - DYNFLIGHT
    CARRID
    CONNID
    As you see above I am trying to create 'DYNFLIGHT' along with the 2 attributes which are inside this node. The structure of the node that is, no.of attributes may vary based on some condition. Thats why I am trying to create a node dynamically.
    Also I cannot define the structure in the ABAP dictionary because it changes based on condition
    Message was edited by: gopalkrishna baliga

  • How many 'seats' are included with Adobe Creative Cloud for teams?

    How many 'seats' are included with Adobe Creative Cloud for teams?

    Hi Mrfrodo,
    There isn't a set number, you purchase the number you would need based on the size of your organization.
    This section of the FAQ might also be helpful for you to learn more about team too.
    http://www.adobe.com/products/creativecloud/faq.html#ccm-teams
    -Dave

Maybe you are looking for